I’ve been successfull using this macro for downloading pictures and renaming them with a text included in a related cell:
URLs are in column E, filenames in column F
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As LongLong, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As LongLong, ByVal lpfnCB As LongLong) As LongLong
Sub ScaricaImnmagini()
Dim strSavePath As String
Dim URL As String, ext As String
Dim buf, Ret As LongLong
Dim miorange As Range
Dim cll As Range
Set miorange = Range("e2:e10") '<--- Example
For Each cll In miorange
URL = cll.Value strSavePath = ThisWorkbook.Path & "" & cll.Offset(0, 1).Value& "." & "jpg"
Ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
Next cll
End Sub
The code does not workg for cells with spaces or / symbols.
Es. it saves and renames a cell where text is “ABC”, it does not work for cells where origin text is “ABC 1”.
I’ve tried changing to .Text instead of .Value, with no success.
New contributor
Federico Bellani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.