Insert a User-Selected Image into an Excel VBA UserForm
Question details
Let users select an image from their computer, preview it in an Excel VBA UserForm, and save its path with a worksheet record.

- Product
- Microsoft Excel VBA UserForm
- Device & OS
- not provided
- Scenario
- A UserForm collects information for a worksheet database and needs an image preview before the record is saved.
- Observed behavior
- The desired result is to display the selected image in the form and associate its file path with the saved record.
Save the workbook as a macro-enabled Excel workbook (.xlsm) and enable macros only if you trust the workbook. Prepare a BMP image for testing and create a worksheet named Database with headers in cells A1 and B1.
Use a file picker and Image control in the UserForm
Use this approach to preview a selected BMP image and save its path alongside a record identifier.
This example stores the file path, not the image itself. The image must remain accessible at that path if you want to load it again later.
In Excel, press Alt+F11 to open the VBA editor. Insert or open a UserForm, then use the Toolbox to add an Image control named Image1, a TextBox named TextBox1, and two CommandButtons named cmdBrowse and cmdSave. Set Image1's PictureSizeMode property to 3 - fmPictureSizeModeZoom in the Properties window.
Double-click cmdBrowse and add this code to the UserForm's code window: Private Sub cmdBrowse_Click() Dim picker As Office.FileDialog Dim picPath As String On Error GoTo ImageError Set picker = Application.FileDialog(msoFileDialogFilePicker) With picker .Title = "Select an image" .AllowMultiSelect = False .Filters.Clear .Filters.Add "Bitmap images", "*.bmp" If .Show <> -1 Then Exit Sub picPath = .SelectedItems(1) End With Set Me.Image1.Picture = LoadPicture(picPath) Me.Tag = picPath Exit Sub ImageError: MsgBox "The image could not be loaded: " & Err.Description, vbExclamation End Sub
In the same UserForm code window, add the following procedure. Enter a record identifier in TextBox1 before clicking cmdSave; the identifier goes in column A and the image path goes in column B. Private Sub cmdSave_Click() Dim ws As Worksheet Dim nextRow As Long If Trim(Me.TextBox1.Value) = "" Or Me.Tag = "" Then MsgBox "Enter a record ID and select an image first.", vbExclamation Exit Sub End If Set ws = ThisWorkbook.Worksheets("Database") nextRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1 ws.Cells(nextRow, "A").Value = Me.TextBox1.Value ws.Cells(nextRow, "B").Value = Me.Tag MsgBox "Record added. Save the workbook to keep your changes.", vbInformation End Sub
Select the UserForm in the VBA editor and press F5. Enter an ID, click cmdBrowse to select a BMP image, and click cmdSave. Check the new row on the Database worksheet, then save the workbook.

Manage worksheet records with WPS Spreadsheets
WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheet records. Its format compatibility makes it easy to move everyday files from Microsoft Office; keep using Excel for this VBA UserForm workflow unless you have verified macro support in your WPS installation.

Frequently Asked Questions
How do I make the image fit inside the UserForm control?
Select Image1 in the VBA editor and set PictureSizeMode to 3 - fmPictureSizeModeZoom in the Properties window. This scales the picture to fit while preserving its proportions.
Does saving the path embed the image in the workbook?
No. The example writes the selected file path to the Database worksheet. Moving or deleting the image can make that path unusable; consider copying images to a managed folder if the records need stable paths.
Can I select a PNG or JPG instead of a BMP?
LoadPicture support varies by format and environment, and PNG is not reliably supported. Test the formats you need before changing the file picker's Filters.Add line, or convert images to BMP for this example.
Why does the code look for a Database worksheet?
The save procedure uses ThisWorkbook.Worksheets("Database") as its destination. Create a worksheet with that name, or change the name in the code to match your existing database sheet.




