PDA

View Full Version : VBA to download images in web



plakatax
04-04-2016, 07:30 AM
Hi Excel Gurus,


Good day.


I have below code to download JPG files in web. Its currently working but i need to have it worked if i want to download many images and i have many links.


Here is the entire code: This code download image and saving it in desktop


Option Explicit


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


Sub getJPGfromweb()
Dim strJPGLink As String
Dim strJPGFile As String
Dim Result As Boolean
strJPGLink = ActiveSheet.Range("B7").Value
strJPGFile = ActiveSheet.Range("F7").Value
Result = DownloadFile(strJPGLink, strJPGFile)
MsgBox Result
End Sub


Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function




Please help as i have many links in column B. I want the macro to work as long as there is a value in B and save it in specific folder and not in desktop.


Thanks a lot in advance!


Mike