Bonjour à tous,

J'ai dernièrement découvert que l'on pouvait piloter internet depuis VBA chose que je n'imaginais pas auparavant. J'aimerais donc piloter un site internet afin d'y saisir automatiquement des données à l'aide d'une macro.

En regardant un peu sur le net j'ai recompilé une macro qui permet d'ouvrir un site style "boursorama", puis d'y saisir des infos. Cependant quand j'essai de la faire fonctionner sur le site en question (celui que je voudrais piloter) elle ne fonctionne pas.

En fait j'aimerais pouvoir faire une bouble afin que VBA me répertorie tous les liens possibles et plus particulièrement des liens de types URL. Quand je click droit sur les liens de ce site puis regarde properties, il est écrit: "adresse URL:javascript: toggle_branch('TRADE_CAPTURE')". C'est ce genre de lien que j'aimerais activer.
Comment simuler un click et activer ces liens afin de naviguer?

De plus, lorsque je me connecte à ce site, il me faut rentrer un Id et mot de passe dans une fenêtre "pop up" j'ai essayé plein de trucs mais rien n'y fait.

QQun a t'il une réponse à mon problème?

Merci de votre aide

Anthony

Mon code est le suivant, la fonction principale est Sub Explorer Test? J'ai mis un lien là où ça commence à déconner il me semble.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Function GetOpenIEByTitle(i_Title As String, _
                                  Optional ByVal i_ExactMatch As Boolean = True) As SHDocVw.InternetExplorer
'finds an open IE site by checking the title
Dim objShellWindows As New SHDocVw.ShellWindows
 
  If i_ExactMatch = False Then i_Title = "*" & i_Title & "*"
  'ignore errors when accessing the document property
  On Error Resume Next
  'loop over all Shell-Windows
  For Each GetOpenIEByTitle In objShellWindows
    'if the document is of type HTMLDocument, it is an IE window
    If TypeName(GetOpenIEByTitle.document) = "HTMLDocument" Then
      'check the title
      If GetOpenIEByTitle.document.Title Like i_Title Then
        'leave, we found the right window
        Exit Function
      End If
    End If
  Next
End Function
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'loads a web page and returns True or False depending on
'whether the page could be loaded or not
Function LoadWebPage(i_IE As SHDocVw.InternetExplorer, _
                             i_URL As String) As Boolean
  With i_IE
    'open page
    .navigate i_URL
    'wait until IE finished loading the page
    Do While .readyState <> READYSTATE_COMPLETE
      Application.Wait Now + TimeValue("0:00:05")
    Loop
    'check if page could be loaded
    If .document.URL = i_URL Then
      LoadWebPage = True
    End If
  End With
End Function

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
'returns new instance of Internet Explorer
Function GetNewIE() As SHDocVw.InternetExplorer
  'create new IE instance
  Set GetNewIE = New SHDocVw.InternetExplorer
  'start with a blank page
  GetNewIE.Navigate2 "about:Blank"
End Function
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Sub ExplorerTest()
Const myPageTitle As String = "FundManager"
Const myPageURL As String = "http://bftparis/"
Const mySearchForm As String = "searchform"
Const mySearchInput As String = "searchInput"
Const mySearchTerm As String = "Document Object Model"
Const myButton As String = "Go"
 
Dim myIE As SHDocVw.InternetExplorer
 
  'check if page is already open
  Set myIE = GetOpenIEByTitle(myPageTitle, False)
 
  If myIE Is Nothing Then
    'page isn't open yet
    'create new IE instance
    Set myIE = GetNewIE
    'make IE window visible
    myIE.Visible = True
    'load page
    If LoadWebPage(myIE, myPageURL) = False Then
      'page wasn't loaded
      MsgBox "Couldn't open page"
      Exit Sub
    End If
  End If
  '
         '***********TOUT FONCTIONNE JUSQU ICI*************
 
    Dim maPageHtml As HTMLDocument
    Dim Helem As IHTMLElementCollection
    Dim Hsel As IHTMLElementCollection
 
    Set maPageHtml = myIE.document
    Set Helem = maPageHtml.getElementsByTagName("input")
    Set Hsel = maPageHtml.getElementsByTagName("select")
 
    'boucle pour lister les objets type "input" de la page
    'afin d'identifier ls champs qui t'interessent.
    'Les objets Input peuvent etre des textbox ou des boutons
    For i = 0 To Helem.Length - 1
    MsgBox Helem(i).getAttribute("name") & " / " & Helem(i).getAttribute("value")
    'Helem(i).innerText = "testtesttesttesttesttest"
    Next
    'Helem(4).Click
  '
End Sub