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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
| Sub récup_cours_reuter()
Application.DisplayAlerts = False
Application.ScreenUpdating = True
On Error Resume Next
Dim ie As InternetExplorer, IEDoc As HTMLDocument, InputboursoramaZoneTexte As HTMLInputElement, FormboursoramaCherche As DispHTMLElementCollection
Dim htmlProfil As HTMLGenericElement, Element As IHTMLElementCollection, Element2 As IHTMLElementCollection, Cotation As HTMLSpanElement
Dim htmlSelectElem As HTMLSelectElement, htmlGeneric As HTMLGenericElement, cours As HTMLGenericElement
Dim DOCelement As HTMLGenericElement, validation As HTMLGenericElement, maTable As IHTMLTable
Dim Htable As IHTMLElementCollection, lienFtid As HTMLLinkElement, lienFtid2 As HTMLLinkElement
'Initialisation des variables
FindAndTerminate "IExplore.exe"
Set ie = CreateObject("InternetExplorer.Application")
'Chargement d'une page Web
ie.navigate "https://monsite.fr"
'On attend le chargement complet de la page
WAITIE1 ie
'Affichage de la fenêtre IE en visible
ie.Visible = True
On Error GoTo A
'iedoc deviens le document
Set IEDoc = ie.document
''''''''''''''''''''''''saisie login et mp
Set DOCelement = IEDoc.getElementsByName("UserId").Item
DOCelement.Value = "******"
'''''''''''''''''''''''''''saisie de MDP
Set DOCelement = IEDoc.getElementsByName("Password").Item
DOCelement.Value = "*****"
DOCelement.Select
''''''''''''''''''''''''validation
Set validation = IEDoc.forms(0)
validation.submit
Application.Wait (Now + TimeValue("0:00:02"))
WAITIE1 ie
A:
With Sheets("Feuil1")
derligne = .Range("A" & Rows.Count).End(xlUp).Row
For z = 2 To derligne
monisin = .Range("A" & z).Value
Set IEDoc = ie.document
'On pointe notre Zone de texte
Set helem = IEDoc.getElementById("go")
helem.Value = .Range("A" & z).Value
'es tu obligé de cliquer a chaque remplissage de tes "GO"?
'reponse : OUi car la recherche se fait sur plusieurs codes placés dans la 'colonne A, je dois donc valider la recherche a chaque fois
Set helem = IEDoc.getElementById("go-submit")
helem.Click
'SendKeys ("{ENTER}") 'enter
WAITIE1 ie
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'boucle pour trouver le code isin et cliquer dessus
'On pointe le document
Set IEDoc = ie.document
' WAITIE ie
For i = 0 To IEDoc.Links.Length - 1
'On pointe notre lien
'Set lienFtid = IEDoc.anchors(2)
'On Error Resume Next
Set lienFtid = IEDoc.Links(i)
If IEDoc.Links(i).innerText = monisin Then
'On exécute le lien
IEDoc.Links(i).Click
'On attend le chargement complet de la page
WAITIE2 ie
Exit For
End If
Next i
'boucle pour trouver le price history et cliquer dessus
Set IEDoc = ie.document
'On pointe le document
For u = 0 To IEDoc.Links.Length - 1
Set lienFtid2 = IEDoc.Links(u)
If IEDoc.Links(u).innerText = "Price History" Then
'On exécute le lien
IEDoc.Links(u).Click
'"""""""""""""""
WAITIE2 ie
Exit For
End If
Next u
Dim htmlTagCol As IHTMLElementCollection
Dim Generic As HTMLGenericElement
Set IEDoc = ie.document
'On liste les éléments de type td
Set htmlTagCol = IEDoc.getElementsByTagName("td")
Range("B" & z).Value = htmlTagCol.Item(16).innerText
'objet type table
'Set htmlTabElement = getElementsByClassName(GenericElem, "RDS-EditHeaderBorder", False)
'Set Element = IEDoc.getElementsByTagName("TD")
'6eme tableau dans la page Web
'Set IEDoc = ie.document
'For k = 1 To Element.Length
'If Element.item1.innerText = "20130125" Then
'MsgBox "oui, trouvé"
'End If
'On Error Resume Next
'Set maTable = Htable(k)
'datereuter = maTable.Rows(1).Cells(0).innerText
'midprice = maTable.Rows(1).Cells(5).innerText
'Interdata3 = maTable.Rows(2).Cells(0).innerText
'bidprice = maTable.Rows(2).Cells(5).innerText
'Next k
Next z
End With
ie.Quit
'On libère les variables
Set ie = Nothing
Set IEDoc = Nothing
Set ie = Nothing
Set IEDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function WAITIE1(ie)
Application.Wait (Now + TimeValue("0:00:02"))
Do Until ie.readyState = READYSTATE_COMPLETE
SendKeys ("{ENTER}") 'enter
DoEvents
Loop
Set IEDoc = ie.document
Do Until IEDoc.readyState = "complete"
SendKeys ("{ENTER}") 'enter
DoEvents
Loop
End Function
Function WAITIE2(ie)
'Application.Wait (Now + TimeValue("0:00:03"))
Do Until ie.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set IEDoc = ie.document
Do Until IEDoc.readyState = "complete"
DoEvents
Loop
End Function
Sub FindAndTerminate(ByVal strProcName As String)
On Error Resume Next
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcName & "'")
If colProcess.Count > 0 Then
For Each objProcess In colProcess
objProcess.Terminate
Next objProcess
End If
End Sub |
Partager