Computer Learning Zone CLZ Access Excel Word Windows

Peace is good for business.

-35th Rule of Acquisition
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
Home > Code Vault > Access VBA > Download
URL Download to File (Free)
By Richard Rost   Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   2 years ago

This code will download a file from the web at whatever URL you specify and save it as a file on your hard drive. Typically used for images (PNG, JPG, etc.) but you can use it for ZIP files or whatever you choose. Place in global module.


Public 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

Public Function MyDownload(URL As String) As String

    Dim LocalFile As String, Result As Long
    LocalFile = "G:\My Drive\Test.JPG"
    Result = URLDownloadToFile(0, URL, LocalFile, 0, 0)
    If Result = 0 Then
        MyDownload = LocalFile
        MyDownload = ""
    End If

End Function


Place an image control on a form and set its control source to either of these. The first option would be if you had the location of the image URL in a field called WebAddress. The second one is to hard-code the URL in the function.

Another Example

This will download a 200x200 QR code saying "" from Google Charts and save it as C:\QRCode.PNG

    URLDownloadToFile 0, "" & _
            "chs=200x200&cht=qr", "C:\QRCode.PNG", 0, 0


See Also


Comments for URL Download to File (Free)
Age Subject From
2 yearsURLDownLoadToFileAnthony Challoner


Start a NEW Conversation
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
Subscribe to URL Download to File (Free)
Get notifications when this page is updated

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
My Account
My Courses
Lost Password
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Customer Support
Web Site Tour
Consulting Services
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn
Copyright 2023 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/20/2023 1:07:21 PM.
Keywords: code vault access urldownloadtofile download file from web download qr code from google charts download a file  PermaLink  URL Download to File (Free)