Re : Macro qui ne fonctionne pas au boulot
Voici le code :
Function valo_Boursorama(cod)
'renvoie le cours selon B, ou bien "" si échec
Dim texte_code As String * 200
page_à_lire = "http://www.boursorama.com/cours.phtml?symbole=" & cod
encr:
internet = 0
'boucle jusqu'à trouver une connexion internet
Do While internet = 0
internet = OuvreInternet("toto", 1, vbNullString, vbNullString, 0)
Application.Wait Now + 0.5 / 24 / 3600
Loop
URL = 0
'ouvre la page Web
URL = Ouvrepage(internet, page_à_lire, vbNullString, ByVal 0&, &H80000000, ByVal 0&)
Application.Wait Now + 0.5 / 24 / 3600
'lit le texte de la page jusqu'à trouver "dernier"
txtlu = ""
Do While InStr(txtlu, "<td>Dernier</td>") = 0 And InStr(txtlu, "</HTML>") = 0
code_page URL, texte_code, 200, nb_caractères_lus 'ajoute 200 caractères par sécurité
txtlu = txtlu & Left(texte_code, nb_caractères_lus)
If InStr(txtlu, "<HTML>") = 0 Then Exit Do
Loop
code_page URL, texte_code, 200, nb_caractères_lus
txtlu = txtlu & Left(texte_code, nb_caractères_lus)
fermeInternet URL 'ferme la page
fermeInternet internet 'ferme Internet
'si la page n'est pas une page B, recommencer
If InStr(Left(txtlu, 40), "Boursorama") <= 0 Then GoTo encr
valo_Boursorama = ""
'rechercher le nb qui est après "<td>Dernier</td>" et qui se termine par (c)
If InStr(txtlu, "<td>Dernier</td>") > 0 And InStr(txtlu, "(c)") > InStr(txtlu, "<td>Dernier</td>") Then
txtlu = Right(txtlu, Len(txtlu) - InStr(txtlu, "<td>Dernier</td>") - 16 + 1)
'chercher le premier nb
Do While Not IsNumeric(Left(txtlu, 1))
txtlu = Right(txtlu, Len(txtlu) - 1)
Loop
'chercher le cours de bourse
txtlu = Left(txtlu, InStr(txtlu, "(c)") - 1)
If IsNumeric(txtlu) Then valo_Boursorama = 1 * txtlu
End If
End Function