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
| Public Declare Function OuvreInternet Lib "wininet" _
Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, _
ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function fermeInternet Lib "wininet" _
Alias "InternetCloseHandle" (ByVal hInet As Long) As Integer
Public Declare Function Ouvrepage Lib "wininet" _
Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, _
ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Public Declare Function code_page Lib "wininet" _
Alias "InternetReadFile" (ByVal hFile As Long, ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Function valo_Euronext(sicovam)
'renvoie le cours selon Euronext, ou bien "" si échec
Dim texte_code As String * 1024
sicovam = Right("00" & sicovam, 5)
page_à_lire = "http://www.bourse-de-paris.fr/servlet/market8.ValueResult?xls=ok&search=" & sicovam & "&lang=fr"
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
URL = Ouvrepage(internet, page_à_lire, vbNullString, _
ByVal 0&, &H80000000, ByVal 0&) 'ouvre la page Web
Application.Wait Now + 0.5 / 24 / 3600
'lit le texte de la page
code_page URL, texte_code, 1024, nb_caractères_lus
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 Euronext, recommencer
If InStr(txtlu, "Code") = 0 Then GoTo encr
valo_Euronext = ""
'rechercher le numéro de sicovam, puis les tab
If InStr(txtlu, sicovam) > 0 Then
txtlu = Right(txtlu, Len(txtlu) - InStr(txtlu, sicovam) - 1)
txtlu = Right(txtlu, Len(txtlu) - InStr(txtlu, Chr(9))) 'tab
txtlu = Right(txtlu, Len(txtlu) - InStr(txtlu, Chr(9))) 'tab
If txtlu <> "" Then txtlu = Left(txtlu, InStr(txtlu, Chr(9)) - 1)
If IsNumeric(txtlu) Then valo_Euronext = 1 * txtlu
End If
End Function |
Partager