-1

Hi I'm trying to download a zip in a local server using VBA. My code works great in my PC but at the server doesn't work. Heres's the code:

PS. 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

Any suggestion? Thanks so much

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)