Computer Learning Zone CLZ Access Excel Word Windows

One of the biggest problems with the world today is that we have large groups of people who will accept whatever they hear... just because it suits their worldview, not because it is actually true or because they have evidence to support it.

-Neil deGrasse Tyson
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > Code Vault > Access VBA > Download
URL Download to File (Free)
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   3 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.

Source

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
    Else
        MyDownload = ""
    End If

End Function


Usage

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 "599cd.com" from Google Charts and save it as C:\QRCode.PNG

    URLDownloadToFile 0, "https://chart.googleapis.com/chart?chl=599cd.com&" & _
            "chs=200x200&cht=qr", "C:\QRCode.PNG", 0, 0

Video

See Also

 

Comments for URL Download to File (Free)
 
Age Subject From
3 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
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.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/21/2024 6:30:13 AM. PLT: 1s
Keywords: code vault access urldownloadtofile download file from web download qr code from google charts download a file  PermaLink  URL Download to File (Free)