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
|
Private Declare Function URLDownloadToFile _
Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Sub U1000_TelechargeFichier(ByVal URLSource As String, ByVal FichierSource As String, _
ByVal LienFichierLocal As String)
Dim IE As InternetExplorer
Dim PageInternet As HTMLDocument
Dim Element As HTMLAnchorElement
Dim ReponseAPI As Long
Dim FichierTrouve As Boolean
Set IE = New InternetExplorer
IE.Navigate URLSource
IE.Visible = False: IE.Top = 0: IE.Left = 0
'on attend l'ouverture complète de la page web
Do Until IE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set PageInternet = IE.Document
FichierTrouve = False
For Each Element In PageInternet.getElementsByTagName("a")
If FichierSource = Element.innerText Then
FichierTrouve = True
Element.Click
Do Until IE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
ReponseAPI = URLDownloadToFile(0&, Element.href, LienFichierLocal, 0&, 0&)
'ReponseAPI = URLDownloadToFile(0&, URLSource & FichierSource, LienFichierLocal, 0&, 0&)
Exit For
End If
Next Element
IE.Quit
Set Element = Nothing
Set PageInternet = Nothing
Set IE = Nothing
If Not FichierTrouve Then
MsgBox ("Le fichier " & FichierSource & _
" n'a pas été trouvé depuis l'adresse " & URLSource & Chr(13) & "Le traitement s'arrête ici !!")
L9000_FinTraitement
ElseIf ReponseAPI <> 0 Or Dir(LienFichierLocal) = "" Then
MsgBox ("Le téléchargement du fichier " & FichierSource & _
" a échoué depuis l'adresse " & URLSource & Chr(13) & "Le traitement s'arrête ici !!")
L9000_FinTraitement
End If
End Sub |
Partager