Option Explicit
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
Private Sub Form_Load()
' source
Const sUrl As String = "http://www.vbfrance.com/gfx/logos/logovb.gif"
' destination (app.path + nom du fichier distant)
Dim sDest As String
sDest = App.Path
If RightB$(sDest, 2) <> "\" Then
sDest = sDest & "\"
End If
sDest = sDest & Mid$(sUrl, 1 + InStrRev(sUrl, "/"))
' download
If URLDownloadToFile(0&, sUrl, sDest, 0&, 0&) = 0 Then
MsgBox "Fichier téléchargé :" & vbNewLine & sDest, vbInformation, "Réussite"
Else
MsgBox "Erreur lors du téléchargement", vbExclamation, "Echec"
End If
End Sub