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:

<br />
Option Explicit</p>
<p>Private Declare PtrSafe Function URLDownloadToFile Lib &quot;urlmon&quot; _<br />
Alias &quot;URLDownloadToFileA&quot; (ByVal pCaller As Long, _<br />
ByVal szURL As String, ByVal szFileName As String, _<br />
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long</p>
<p>Dim Ret As Long</p>
<p>Sub Sample()<br />
    Dim FolderName As String<br />
    Dim ws As Worksheet<br />
    Dim LastRow As Long, i As Long<br />
    Dim strPath As String<br />
FolderName = Range(&quot;$B$2&quot;).Value<br />
    Set ws = Sheets(&quot;Sheet1&quot;)</p>
<p>    LastRow = ws.Range(&quot;A&quot; &amp; Rows.Count).End(xlUp).Row</p>
<p>    For i = 4 To LastRow<br />
        strPath = FolderName &amp; ws.Range(&quot;A&quot; &amp; i).Value &amp; &quot;.jpg&quot;</p>
<p>        Ret = URLDownloadToFile(0, ws.Range(&quot;B&quot; &amp; i).Value, strPath, 0, 0)</p>
<p>        If Ret = 0 Then<br />
            ws.Range(&quot;C&quot; &amp; i).Value = &quot;Downloaded&quot;<br />
        Else<br />
            ws.Range(&quot;C&quot; &amp; i).Value = &quot;Error&quot;<br />
        End If<br />
    Next i<br />
End Sub</p>
<p>

Sample File:

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