Select JPG and PNG Files for an Excel VBA ActiveX Image Control
Question details
Open a specific folder with a VBA file picker, filter for image files, and load a selected image into an ActiveX Image control.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A user wants to select an image from a known folder using a button on an Excel VBA UserForm.
- Observed behavior
- The file picker should list JPG, JPEG, PNG, and GIF files, and a supported selection should appear in the Image control.
Use Excel for Windows with a macro-enabled workbook and a UserForm containing a CommandButton named CommandButton1 and an Image control named Image1. Replace the example folder path with an existing folder; ActiveX controls are not supported in Excel for Mac.
Use a VBA file picker to load an image into a UserForm
Use this method to open a specific folder, show common image formats, and load a supported file into an ActiveX Image control.
The filter determines which files appear in the picker; it does not guarantee that VBA's LoadPicture function can decode every listed format. PNG support is not reliable, so convert a PNG to JPG or BMP if loading fails.
In Excel, press Alt+F11, open your UserForm in the VBA editor, and double-click CommandButton1 to open its Click event.
Replace the Click event with the following code and change C:\YourFolder\ to your folder path: Private Sub CommandButton1_Click() On Error GoTo ImageLoadError With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = False .Filters.Clear .Filters.Add "Picture files", "*.jpg;*.jpeg;*.png;*.gif" .InitialFileName = "C:\YourFolder\" If .Show = -1 Then Me.Image1.Picture = LoadPicture(.SelectedItems(1)) End If End With Exit Sub ImageLoadError: MsgBox "The selected image could not be loaded. Try converting it to JPG or BMP.", vbExclamation End Sub
Run the UserForm from the VBA editor, click CommandButton1, and select an image. Canceling the dialog leaves the current picture unchanged.

Work with spreadsheet images in WPS Office
WPS Office is a free, lightweight alternative for everyday spreadsheet work. Its familiar interface and Microsoft Office format compatibility make it easy to move common files and insert images, although it does not fix Excel ActiveX or VBA compatibility issues.

Frequently Asked Questions
Why does a PNG appear in the picker but fail to load?
The FileDialog filter only controls which filenames are shown. VBA LoadPicture does not reliably support PNG files, so convert the image to JPG or BMP and select the converted file.
How do I change the folder that opens first?
Change the path in .InitialFileName to an existing folder, such as C:\Pictures\. Include the trailing backslash so the dialog opens the folder rather than treating the last part as a filename.
What happens if I cancel the file picker?
The code checks whether .Show returns -1 before loading a file. If you click Cancel, no new picture is loaded and the current Image1 picture remains unchanged.
Can I use this code for an ActiveX Image control on a worksheet?
The example uses Me.Image1 on a UserForm. For worksheet controls, put the button event in the worksheet's code module and refer to the image through Me.OLEObjects("Image1").Object.Picture instead.




