Load a Picture from a URL into an Excel VBA UserForm
Question details
Display a picture from a URL or worksheet in an Excel VBA UserForm Image control.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A UserForm needs to show a specific picture referenced by a URL or already displayed on a worksheet.
- Observed behavior
- The Image control requires a picture object, while pictures placed on a worksheet are typically shapes rather than image objects stored directly in cells.
Identify the direct URL or local file path for the picture and add an Image control named Image1 to the UserForm. The download example requires Windows Excel, access to the URL, and permission to run trusted macros.
Download the URL image and load it into the UserForm
Use this Windows VBA approach to download a supported image file before displaying the UserForm.
LoadPicture reads a local file and returns the picture object required by the Image control; it does not load an image directly from a URL. Use a direct image URL and a format supported by LoadPicture, such as BMP or a compatible JPG.
In Excel, press Alt+F11, choose Insert > Module, and add this Windows API declaration: #If VBA7 Then Public Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As LongPtr, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As LongPtr) As Long #Else Public 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 #End If
In the VBA editor, open the UserForm's code window and add the following. Replace the example URL with a direct link to a trusted BMP image: Private Sub UserForm_Initialize() Dim imageUrl As String Dim imagePath As String Dim result As Long imageUrl = "https://example.com/image.bmp" imagePath = Environ$("TEMP") & "\userform_image.bmp" result = URLDownloadToFile(0, imageUrl, imagePath, 0, 0) If result <> 0 Then MsgBox "The image could not be downloaded." Exit Sub End If On Error GoTo LoadError Me.Image1.Picture = LoadPicture(imagePath) Exit Sub LoadError: MsgBox "The downloaded file could not be loaded as a picture." End Sub
Save the workbook as a macro-enabled .xlsm file, then run the UserForm from the VBA editor. Confirm that Image1 displays the downloaded picture.

Load an existing local picture into the UserForm
Use this option when the image is already saved on disk and downloading it in VBA is unnecessary.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Microsoft Office formats, making it easy to move everyday documents between office suites. It does not fix Excel-specific VBA UserForm issues; macro support and compatibility can vary.

Frequently Asked Questions
Can LoadPicture open an image URL directly?
No. Download the image to a local file first, then assign it with Me.Image1.Picture = LoadPicture(localPath).
How do I show a picture that is already on a worksheet?
If you have the original image file, use its path with LoadPicture in the UserForm code. A worksheet picture is typically a shape, so extracting an embedded picture for use in the control requires a separate method.
Why will my PNG not load in the UserForm?
VBA LoadPicture does not reliably support PNG. Convert the image to a supported format such as BMP, or use additional GDI+ code to handle PNG.
Does the URL download example work on a Mac?
No. The example calls the Windows urlmon library. On another platform, save a supported image locally and use LoadPicture where supported, or use a platform-specific download method.




