Download Website Images from URLs with Excel VBA
Question details
Download image files from direct URLs listed in Excel worksheet cells.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A worksheet contains image URLs that need to be saved as local files.
- Observed behavior
- Each accessible direct image URL is retrieved and saved to a selected folder.
Use Excel for Windows and place direct image URLs in cells A1:A6 of the worksheet you want to process. Create or choose a destination folder, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm).
Download images with an Excel VBA macro
Use this method to retrieve direct image URLs from the active worksheet and save the files in a folder you select.
The macro uses Microsoft XMLHTTP to request each URL and ADODB.Stream to write the response bytes. It accepts JPEG, PNG, GIF, WebP, and BMP content types and reports failed downloads in the VBA Immediate window.
This method requires Excel for Windows and access to the Windows COM components used by the macro. It does not extract URLs from HTML or download images that require a login.
In Excel, open the workbook and press Alt+F11. In the VBA editor, select Insert > Module.
Paste this code into the module: Sub DownloadWebsiteImages() Dim folderPicker As Object, ws As Worksheet, r As Range Dim http As Object, stream As Object Dim folder As String, url As String, contentType As String, ext As String Dim downloaded As Long, failed As Long Set ws = ActiveSheet Set folderPicker = Application.FileDialog(4) folderPicker.Title = "Choose a folder for the images" If folderPicker.Show <> -1 Then Exit Sub folder = folderPicker.SelectedItems(1) & "\" For Each r In ws.Range("A1:A6") url = Trim$(CStr(r.Value)) If Len(url) > 0 Then On Error GoTo FailedRow Set http = CreateObject("Microsoft.XMLHTTP") http.Open "GET", url, False http.Send If http.Status <> 200 Then Err.Raise vbObjectError + 1, , "HTTP status " & http.Status contentType = LCase$(http.getResponseHeader("Content-Type")) If InStr(contentType, ";") > 0 Then contentType = Left$(contentType, InStr(contentType, ";") - 1) Select Case Trim$(contentType) Case "image/jpeg": ext = ".jpg" Case "image/png": ext = ".png" Case "image/gif": ext = ".gif" Case "image/webp": ext = ".webp" Case "image/bmp": ext = ".bmp" Case Else: Err.Raise vbObjectError + 2, , "Unsupported content type: " & contentType End Select Set stream = CreateObject("ADODB.Stream") stream.Type = 1 stream.Open stream.Write http.responseBody stream.SaveToFile folder & "image_" & r.Row & ext, 1 stream.Close Set stream = Nothing downloaded = downloaded + 1 End If NextRow: On Error GoTo 0 Next r MsgBox downloaded & " downloaded; " & failed & " failed." Exit Sub FailedRow: failed = failed + 1 Debug.Print "Row " & r.Row & ": " & Err.Description On Error Resume Next If Not stream Is Nothing Then stream.Close Set stream = Nothing Resume NextRow End Sub
Return to the worksheet containing the URLs, press Alt+F8, select DownloadWebsiteImages, and click Run. Choose the destination folder when prompted.
Open the selected folder to find files named by worksheet row, such as image_1.jpg. For failures, open the VBA editor and press Ctrl+G to view the Immediate window.

Manage image URL lists in WPS Spreadsheet
WPS Office is a free, lightweight Office alternative with a familiar interface for working with spreadsheets and moving between common Office formats. The Windows Excel VBA macro above depends on Microsoft COM components and is not guaranteed to run in WPS.

Frequently Asked Questions
Can the macro download images from a web page URL?
No. Each cell must contain a direct image URL. If a cell contains HTML, extract the image URL from an img src or relevant hyperlink href first.
How do I download URLs from a different range?
In the VBA editor, change ws.Range("A1:A6") to the range containing your URLs, such as ws.Range("B2:B20"), and run the macro from the relevant worksheet.
Why did an image download fail?
The server may require authentication, return a non-200 status, or provide an unsupported Content-Type. A file with the same name may also exist. Press Ctrl+G in the VBA editor to see the reported error.
Why does Excel ask me to enable macros?
Excel can block macros for security. Save the workbook as .xlsm and enable its macros only if you trust the workbook and its code.




