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 Declare Function fermeInternet Lib "wininet" _ Alias "InternetCloseHandle" (ByVal hInet As Long) As Integer 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 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 Sub telecharge() Dim texte_code As String * 1024 fich = InputBox("adresse Internet du fichier à télécharger ?", _ "téléchargement HTTP", "http://jacxl.free.fr/cours_xl/vba/ecriture_japonais.zip") cibl = InputBox("répertoire dans lequel le fichier doit être enregistré ?", _ "téléchargement HTTP", "c:\mes documents") If Right(cibl, 1) <> "\" Then cibl = cibl & "\" 'recherche nom du fichier nom = fich Do While InStr(nom, "/") > 0 nom = Right(nom, Len(nom) - 1) Loop 'connection au fichier à télécharger internet = OuvreInternet("toto", 1, vbNullString, vbNullString, 0) 'ouvre Internet url = Ouvrepage(internet, fich, vbNullString, _ ByVal 0&, &H80000000, ByVal 0&) 'accède au fichier If url = 0 Then MsgBox ("fichier inaccessible"): Exit Sub 'création du fichier local Set fs = CreateObject("Scripting.FileSystemObject") Set fichcibl = fs.OpenTextFile(cibl & nom, 2, True) 'lecture du fichier par paquet de 1024 bytes nb_caractères_lus = 1 Do While nb_caractères_lus > 0 code_page url, texte_code, 1024, nb_caractères_lus txt = Left(texte_code, nb_caractères_lus) fichcibl.write txt Loop 'ménage fermeInternet url 'ferme la page fermeInternet internet 'ferme Internet fichcibl.Close Set fichcibl = Nothing Set fs = Nothing MsgBox "le fichier " & nom & " a été enregistré dans le répertoire " & cibl End Sub