Public Sub IEConnectToURL(ByVal sURL As String)
Const READYSTATE_COMPLETE = 4
Dim IE As Object
Set IE = CreateObject("internetExplorer.Application")
IE.Visible = False
With IE
.Navigate sURL
Do Until .ReadyState = 4
DoEvents
Loop 'attend la fin du chargement
End With
Dim bOk As Boolean
Dim loDoc As HTMLDocument
Set loDoc = IE.Document
DoEvents
Dim ContainerDiv As HTMLDivElement, ResultDIV As HTMLDivElement, SubResultDIV As HTMLDivElement
DoEvents
Set ContainerDiv = loDoc.getElementById("market-data")
DoEvents
For Each ResultDIV In ContainerDiv.getElementsByTagName("div")
If ResultDIV.className = "marketData" Then ' "md-data" Then
'Debug.Print ResultDIV.innerHTML
For Each SubResultDIV In ResultDIV.getElementsByTagName("div")
Debug.Print SubResultDIV.innerText
Next
End If
Next
Set IE = Nothing
End Sub
Sub recupGAZ()
'Nécessite d'activer la référence
'"Microsoft Internet Controls"
'et
'"Microsotf HTML Object Library"
Sheets("Récup Web").[B5].ClearContents
Dim IE As New InternetExplorer
Dim winShell As New ShellWindows
Dim maPageHtml As HTMLDocument
IE.navigate ("http://www.powernext.com/#sk;tp=app;n=market;f=listMarketTable;t=layout/gasSpot;fp=system_name:gasSpot;lang=en_US")
On Error Resume Next
For Each IE In winShell
If IE.LocationURL <> "" Then
Set maPageHtml = IE.document
Sheets("Récup Web").Range("B5") = maPageHtml.DocumentElement.innerText
Set maPageHtml = Nothing
End If
Next IE
On Error GoTo 0
End Sub
Private Sub CommandButton1_Click()
Call IEConnectToURL("www.mapage.bidule.fr/toto")
End Sub