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
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Public Sub Download_All_Images()
Dim downloadToFolder As String
Dim lastRow As Long
Dim URL As Variant
Dim FileName As String
downloadToFolder = "C:\Temp\Excel\images\" 'THIS FOLDER MUST EXIST
If Right(downloadToFolder, 1) <> "\" Then downloadToFolder = downloadToFolder & "\"
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
For Each URL In Range("A2:A" & lastRow)
FileName = downloadToFolder & Mid(URL, InStrRev(URL, "/") + 1)
If Not DownloadFile(CStr(URL), FileName) Then
MsgBox "Error downloading " & URL & " to " & FileName
End If
Next
End Sub
Private Function DownloadFile(URL As String, LocalFileName As String) As Boolean
Dim RetVal As Long
DeleteUrlCacheEntry URL
RetVal = URLDownloadToFile(0, URL, LocalFileName, BINDF_GETNEWESTVERSION, 0)
DownloadFile = (RetVal = 0)
End Function