-1

I'm trying to download a zip in a local server using VBA.

My code works in my PC. At the server I always have "Download failed".

Cell A7 is the link of the download.

Dim downloadStatus As Variant
Dim url As String
Dim destinationFile_local As String

url = [A7]
destinationFile_local = "C:\Users\omayorga\Downloads\" & fileName([A7])

downloadStatus = URLDownloadToFile(0, url, destinationFile_local, 0, 0)

If downloadStatus = 0 Then
    MsgBox "Downloaded Succcessfully!"
Else
    MsgBox "Download failed"
End If

End Sub

Function fileName(file_fullname) As String
    fileName = Mid(file_fullname, InStrRev(file_fullname, "/") + 1)
End Function
Community
  • 1
  • 1
Oscar Mayorga
  • 69
  • 1
  • 4

1 Answers1

1

You have this in your code, you need:

Declare PtrSafe 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

Check your download link, the same said Raymond Wu your destinationFile_local, tested here your code works.

refer link

How do I download a file using VBA (without Internet Explorer)