Download and Rename Images Using Excel

Download images from a URL and easily set image names of the downloaded files using an excel enabled macro file.

Excel Macro source code:

Option Explicit

Private 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

Dim Ret As Long

Sub Sample()
    Dim FolderName As String
    Dim ws As Worksheet
    Dim LastRow As Long, i As Long
    Dim strPath As String
FolderName = Range("$B$2").Value
    Set ws = Sheets("Sheet1")

    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row

    For i = 4 To LastRow
        strPath = FolderName & ws.Range("A" & i).Value & ".jpg"

        Ret = URLDownloadToFile(0, ws.Range("B" & i).Value, strPath, 0, 0)

        If Ret = 0 Then
            ws.Range("C" & i).Value = "Downloaded"
        Else
            ws.Range("C" & i).Value = "Error"
        End If
    Next i
End Sub


Sample File:

By |2018-04-10T10:50:55+00:00September 23rd, 2017|How To's, Tools|