Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
MS Access

Download Images from Web

Use this to get all images from a Webpage and download them to a local folder

In this tutorial I will explain how to download all images on a given webpage to a local folder.

This was originally show as a blog post.

YouTube Link: TIP: Download Images from a Website to a Folder

Create a Form

Add some controls

  • WebBrowser0 - ActiveX Control
  • URL - TextBox
  • lstImages - List Box
  • cmdNavigate - Command Button
  • cmdDownload - Command Button

Share the code here:

	Private Declare 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
	
	Private Sub cmdDownload_Click()
		
		Dim i As Integer
		For i = 0 To lstImages.ListCount - 1
			Download (lstImages.ItemData(i))
		Next i
		
	End Sub
	
	Sub Download(file As String)

		Dim done, pathOfdb, fn, saveTo
		pathOfdb = CurrentProject.Path & "\"
		fn = filename(file)
		saveTo = pathOfdb & fn
		
		MsgBox file
		MsgBox saveTo
		
		done = URLDownloadToFile(0, file, saveTo, 0, 0)
		
		If done = 0 Then
			MsgBox "File has been downloaded!"
		Else
			MsgBox "File not found!"
		End If
		
	End Sub
	
	Private Sub cmdNavigate_Click()
		
		EventRunning = True
		WebBrowser0.Navigate URL
		While EventRunning
			DoEvents
		Wend
		
	End Sub
	
	Private Sub WebBrowser0_DownloadBegin()
		IsNavigating = True
	End Sub
	
	Private Sub WebBrowser0_DownloadComplete()
		
		IsNavigating = False
		Dim Obj
		
		For Each Obj In WebBrowser0.Document.All
			If Obj.TagName = "img" Then
				ImageHTML = ImageHTML & " " & Obj.OuterHTML
				ImageSrc = ImageSrc & " " & Obj.getAttribute("src")
				lstImages.AddItem Obj.getAttribute("src")
			End If
		Next
		
	End Sub
	
	Function filename(src As String)

		Dim val, fn
		'http://www.599cd.com/images/pc-logobar.gif
		val = InStr(StrReverse(src), "/")
		fn = Right(src, val - 1)
		
		filename = fn
		
	End Function
	

I'll look for the original db...


 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

You may want to read these articles from the 599CD News:

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP