Merci pour cette excellente ressource, il m'a été d'une grande aide, mais j'ai un problème avec Excel VBA pour télécharger des fichiers Excel à partir d'un serveur distant. Je soupçonne qu'il est évident que mon code manque. Le problème que j'ai est que tous les fichiers téléchargés ont toujours 15 Ko de taille, indépendamment de la taille ou du contenu du fichier original et tous portent le même contenu qui semble être du texte simplement copié à partir du site Web hôte, plutôt que le fichier que j'essaie de télécharger. J'ai essayé d'utiliser diverses extensions de fichiers, y compris CSV, mais les résultats sont les mêmes. Quand j'ouvre le fichier téléchargé excel dit que le format de fichier et l'extension ne correspondent pas, puis dit que, en raison de problèmes lors du chargement, le fichier est "fichier manquant C: \ remote \ css \ logon.css" et "fichier manquant C: \ remote \ javascript \ ramjsfx.menu.css", qui est grec pour moi.Télécharger le fichier de
Sub DownloadFilefromWeb()
Const E_OUTOFMEMORY As Long = &H8007000E
Const E_DOWNLOAD_FAILURE As Long = &H800C0002
Dim InitialName As String
Dim Msg As String
Dim RegExp As Object
Dim RetVal As Long
Dim SaveName As String
Dim SavePath As String
Dim URL As String
URL = InputBox("Enter the download URL below.", "Download from Internet")
If URL = "" Then Exit Sub
Set RegExp = CreateObject("VBScript.RegExp")
RegExp.IgnoreCase = True
RegExp.Pattern = "^(.*\/)(.+)$"
InitialName = RegExp.Replace(URL, "$2")
Set RegExp = Nothing
If InitialName = "" Or InitialName = URL Then
MsgBox ("Error - Missing File Name")
Exit Sub
End If
SavePath = Application.GetSaveAsFilename(InitialName)
If SavePath = "" Then Exit Sub
'SavePath = "C:\Users\Rob's Laptop\Documents\Test\Test3.xls"
'URL = "https://remote.picosting.co.uk/Remote/fs/files.aspx?path=%5c%5cPISBS2011%5cfiles%5cRob% 20Shaw%27s%20test%20folder%5cTest1"
RetVal = URLDownloadToFile(0&, URL, SavePath, 0&, 0&)
Select Case RetVal
Case 0
Msg = "Download Successful"
Case E_OUTOFMEMORY
Msg = "Error - Out of Mmemory"
Case E_DOWNLOAD_FAILURE
Msg = "Error - Bad URL or Connection Interrupted"
Case Else
Msg = "Unknown Error - " & RetVal
End Select
MsgBox Msg
End Sub
Amitiés
Rob
J'utilise ce code vbscript mais pas VBA. http://vbscriptautomation.net/73/download-files-using-vbscript/ – glh