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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1741107808, '3.142.248.196', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/Win-API/examples/URLDownloadToFile(56): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78