Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

emmanuel75

XLDnaute Junior
Bonsoir à tous,

J'ai programmé une macro qui navigue sur internet ( avec une synthaxe comme :
Dim IE As New InternetExplorer
Dim x As Integer
Dim Doc As HTMLDocument

IE.Navigate ("http://www.monsite.com")

Do Until IE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set Doc = IE.document
For x = 90 To Doc.Links.Length - 1
Cells(x - 89, 1) = Doc.Links(x)
Next

Application.Wait Now() + TimeValue("00:00:05")

End Sub)

Le souci c'est que çà marche sous XP (tout ordi) mais pas sur vista (tout ordi)
une fenêtre d'erreur s'affiche...


pour "Set Doc = IE.document"

Quelqu'un a déjà eu un problème similaire ?????????????

Merci à quiconque me donnera des pistes...

Emmanuel
 
Re : Excel et Vista

Salut le forum

J'ai contourné le problème avec une fonction.
Code:
Public Function IE7Navigate(strURL As String) As SHDocVw.InternetExplorer
Dim theSHD As SHDocVw.ShellWindows
Dim IE7 As SHDocVw.InternetExplorer
Dim i As Long
    
    Set theSHD = New SHDocVw.ShellWindows
    For i = 0 To theSHD.Count - 1
        Set IE7 = theSHD.Item(i)
        If IE7.LocationURL = strURL Then
            IE7.Quit
        End If
    Next
    
    Set IE7 = New SHDocVw.InternetExplorer
    IE7.navigate strURL
    Do
        Set theSHD = New SHDocVw.ShellWindows
        For i = theSHD.Count - 1 To 0 Step -1
            Set IE7 = theSHD.Item(i)
            If IE7.LocationURL = strURL Then Exit Do
        Next
    Loop
    IE7.Visible = False
    Do Until IE7.readyState = READYSTATE_COMPLETE
        DoEvents
    Loop
    Do Until IE7.document.readyState = "complete"
        DoEvents
    Loop
    Set IE7Navigate = IE7
      
End Function
Et dans le code de la macro
Code:
Sub Importer_TableauParisTurf()
'Nécessite d 'activer les references
    'Microsoft HTML Objects Library
    'et
    'Microsoft Internet Controls
Dim maPageHtml As HTMLDocument
Dim Htable As IHTMLElementCollection
Dim maTable As IHTMLTable
Dim IE7 As SHDocVw.InternetExplorer
Dim j As Integer, i As Integer, t As Byte
Dim Ligne As Byte
Dim lien As String
Dim RaceDate As String
Dim Cellule As Range

RaceDate = Format(Date + 1, "yyyy-mm-dd")
lien = "http://www.paris-turf.com/pid56-reunion.html?date=" & RaceDate

    Set IE7 = IE7Navigate(lien)
    
Ligne = 5
Sheets("Requete").Select
Cells.Delete

Set maPageHtml = IE7.document
'objet type table
Set Htable = maPageHtml.getElementsByTagName("table")

For t = 2 To Htable.Length - 1
'boucle tableau dans la page Web
Set maTable = Htable(t)

'boucle sur toutes les lignes du tableau
For i = 2 To maTable.Rows.Length
    'boucle sur les cellules dans chaque ligne
    For j = 1 To 2
        Cells(Ligne + i - 1, j) = maTable.Rows(i - 1).Cells(j - 1).innerHTML
    Next j
Next i

Ligne = Range("A65535").End(xlUp).Row

Next t

Columns("C:IV").Delete

IE7.Quit
Set IE7 = Nothing
Set maPageHtml = Nothing
Set maTable = Nothing

End Sub
Pour avoir le Texte au-lieu du code HTML remplace innerHTML par innerText
A adapter pour ta situation
Mytå
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
8
Affichages
982
Réponses
11
Affichages
3 K
Retour