Search notes:

Downloading a file with VBA (WinAPI function URLDownloadToFile)

option explicit

private 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

sub downloadFile(url as string, destPath as string)
    if URLDownloadToFile(0, url, destPath, 0, 0) <> 0 then
       msgBox "download failed"
    end if
end sub

sub main()
   downloadFile "https://upload.wikimedia.org/wikipedia/commons/6/60/Matterhorn_from_Domh%C3%BCtte_-_2.jpg", environ("userprofile") & "\Matterhorn.jpg"
end sub

See also

Using MSXML2.XMLHTTP to make web requests from VBA.
Other examples that demonstrate using the WinAPI with VBA.

Index