To add an image box to an Excel data-entry form, create or open a VBA UserForm, place an Image control on it, and add a button that lets the user choose a picture. Excel’s built-in Data Form cannot display an image field, so this method uses desktop Excel and a macro-enabled workbook. The form can show a selected photo while someone enters a record; the picture is not automatically saved in a worksheet cell.
What You’ll Need
- Desktop Microsoft Excel for Windows. Excel for the web cannot create or run VBA UserForms. Excel for Mac has VBA, but its form controls and file-picker behavior can differ, so the Windows steps and sample code may need adjustment.
- A workbook you can save as an Excel Macro-Enabled Workbook (.xlsm). Keep a separate backup before adding or running macros; macro changes cannot be undone with Ctrl+Z.
- A VBA UserForm, either one you already use for data entry or a new one, plus a few sample JPG, JPEG, BMP, or GIF images for checking the result. Standard VBA LoadPicture support for PNG is not reliable, so use one of those formats.
- Permission to run macros. In a work or school environment, your organization’s security settings may restrict them.
Step-by-Step
- Save a working copy as an .xlsm file. In Excel, choose File > Save As, select a folder, and choose Excel Macro-Enabled Workbook (*.xlsm) as the file type. If you already have a data-entry workbook, make a copy first. The image box and its button will use VBA, and an .xlsx file does not retain VBA code.
- Open the Visual Basic Editor. In Windows Excel, press Alt+F11. If you do not see the Project Explorer, choose View > Project Explorer. Find your workbook in the project list. To create a fresh form, select the workbook project and choose Insert > UserForm. To add the image to an existing form, double-click that form instead. The Toolbox should appear; if it does not, choose View > Toolbox.
- Add an Image control. In the Toolbox, select the Image control, then drag a rectangle onto the form where the photo should appear. With the control selected, press F4 to show Properties if that panel is hidden. Change its (Name) property to
imgPhoto. Set PictureSizeMode to3 - fmPictureSizeModeZoomif the property list offers that choice. Zoom fits the whole image inside the box while keeping its proportions; it may leave empty space at the sides or top. You can also set a border or adjust the control’s height and width in the form designer. - Add a button for choosing a picture. Select the CommandButton control in the Toolbox and draw it beneath or beside the image box. In Properties, set (Name) to
cmdBrowseand Caption toBrowse for photo.... The names matter: the code below expects those exact names. If you use different names, replace the names in the code to match your controls. - Open the button’s code window. Double-click the new button. Excel opens the UserForm’s code window with a
cmdBrowse_Clickevent procedure. Replace or fill in that procedure with this code. It opens a file picker, allows one selection, loads the image, and remembers the selected file path in the form’s Tag property.
Private Sub cmdBrowse_Click()
Dim picker As Office.FileDialog
Dim selectedFile As String
On Error GoTo LoadError
Set picker = Application.FileDialog(msoFileDialogFilePicker)
With picker
.Title = "Select a photo"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Picture files", "*.jpg;*.jpeg;*.bmp;*.gif"
If .Show <> -1 Then Exit Sub
selectedFile = .SelectedItems(1)
End With
Me.imgPhoto.Picture = LoadPicture(selectedFile)
Me.imgPhoto.PictureSizeMode = fmPictureSizeModeZoom
Me.Tag = selectedFile
Exit Sub
LoadError:
MsgBox "Excel could not load this image. Choose a JPG, BMP, or GIF file.", vbExclamation
End Sub
- Check the control names and compile the code. Return to the form designer and confirm the image control is named
imgPhotoand the button is namedcmdBrowse. In the code window, choose Debug > Compile VBAProject if that command is available. Correct any spelling or control-name errors before trying to run the form. - Open the form from a macro. In the Visual Basic Editor, choose Insert > Module and add a simple launcher. Replace
UserForm1with the form’s actual name if you renamed it. This macro displays the form when run.
Public Sub OpenEntryForm()
' Show the data-entry form.
UserForm1.Show
End Sub
- Test the image box. In the Visual Basic Editor, place the cursor inside
OpenEntryFormand press F5, or return to Excel, press Alt+F8, selectOpenEntryForm, and choose Run. Click Browse for photo…, select a JPG or BMP, and confirm it appears inside the box. Try a second image with a different shape to check that it fits as expected. Save the workbook after you are satisfied. - Connect it to your existing entry workflow. If your form already has fields and a Save or Add Record button, leave that process in place and use the image control as an additional visual field. The sample code keeps the chosen file path in
Me.Tagonly while the form is open. If your records need a lasting photo reference, update your existing save routine to write that path to a worksheet column. The path points to a file on disk; it does not embed the picture in the workbook.
Common Mistakes
Expecting the built-in Data Form to accept a picture. Excel’s built-in Data Form displays fields based on a table’s columns; it does not provide an Image control or photo-upload field. Use a VBA UserForm for an interactive image box, or use a worksheet layout with a picture placed separately if you do not need a picker.
Using mismatched control names. If the code refers to imgPhoto but the control is still called Image1, the procedure will fail. Check the (Name) property, not the Caption shown to users.
Choosing an unsupported image file. A PNG may appear in other Microsoft 365 features but fail with VBA’s LoadPicture. Start with a JPG, JPEG, BMP, or GIF. Also remember that a link to a local photo can break if the file is moved or the workbook is sent to someone who cannot access that folder.
Saving in the wrong format or disabling macros. Save as .xlsm and enable macros only for workbooks you trust. If the file is saved as .xlsx, VBA code is removed when you confirm the format change.
Tips
Keep the image box large enough to identify the photo but avoid making it dominate the form. A landscape box works for many product images; a taller box may suit portraits. Use the zoom setting to avoid stretching faces or objects. Add a short label such as “Item photo” so users understand what belongs there, and consider adding a note that JPG or BMP files work best.
If the photo identifies a record, decide how the workbook will retain that connection. You can store the file path in a dedicated worksheet column and keep images in a shared folder with stable names, or separately embed images in the worksheet using an appropriate process. The sample only previews the selected file, so do not assume the picture is saved when the form closes. Test with a copy of the workbook and representative files before distributing the form.
On Windows, Alt+F11 opens the VBA editor and Alt+F8 lists macros. On Mac, the VBA editor and keyboard shortcuts differ by Excel version and keyboard settings; use the Developer tab or Excel’s Tools > Macro menu where available. VBA UserForms are not available in Excel for the web, so users must open the workbook in desktop Excel to use this form.
Troubleshooting
The Browse button does nothing or shows a compile error: confirm its (Name) is cmdBrowse, that its code is in the correct UserForm module, and that the image control is named imgPhoto. A small spelling difference is enough to stop the event from working. Use Debug > Compile VBAProject to identify syntax issues.
The file picker opens, but the image does not appear: test with a JPG or BMP stored in a local folder. Confirm the file is not damaged, and check that the Image control has visible dimensions and is not covered by another control. If the code displays its error message, try another supported file rather than simply changing the file extension.
The form does not open from Excel: verify that you saved as .xlsm and enabled macros for this trusted workbook. Press Alt+F8 and check that OpenEntryForm appears in the macro list. If it is missing, confirm the launcher is in a standard module, not in the UserForm’s code module, and that it is declared Public.
The code fails on a Mac: the sample is written for Windows desktop Excel. Check that your Mac version supports the required VBA controls and file-picker calls. If it does not, use a platform-appropriate picker or build the form in Windows Excel; the web version cannot run the UserForm.
Frequently Asked Questions
Can I add an image box to Excel’s built-in Data Form?
No. That form is designed for entering values in table columns and does not support an image control. Use a VBA UserForm or create a custom worksheet-based form.
Does the selected picture become part of the workbook?
Not with this sample. It displays the image from its file path while the form is open. To retain a reference, save the path in a record; to keep the actual image with the workbook, use a separate image-embedding process.
Can users select PNG files?
The example filters for JPG, JPEG, BMP, and GIF because VBA’s standard LoadPicture does not reliably load PNG files. Converting the image to a supported format is the simplest fix.
Can I add more than one image box?
Yes. Add another Image control and, if needed, another browse button. Give each control a unique name and create a separate click procedure that loads the selected file into the matching Image control.
Will the form work in Excel for the web?
No. Excel for the web does not run VBA UserForms or their macros. Open the macro-enabled workbook in desktop Excel to use this approach.
Can I use a picture already stored in a worksheet?
You can show a picture on the worksheet, but the sample picker loads a file chosen from disk. To display an existing worksheet picture in a UserForm, the VBA would need to export or otherwise access that image; it is not automatically connected to the Image control.
Related
- Excel Quick Analysis Button: What It Does and How to Use It
- Excel Solver: Find a Target Sum with Changing Cells
- Solver in Excel: How to Enable and Set It Up
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Excel Row Freeze Shortcut and How to Use Freeze PanesIn Excel for Microsoft 365 on Windows, press Alt, then W, F, and R to freeze the top…
- Excel Keyboard Shortcuts to Select Cells and RangesIn Excel for Microsoft 365 on Windows, use Ctrl+A to select the current data region, then press it…
- How to Insert a Row in Excel Above a Selected CellTo insert a worksheet row above a cell in Excel for Microsoft 365 on Windows, select any cell…
- Excel Hyperlink Shortcut: How to Add a LinkTo add a hyperlink in Excel for Microsoft 365 on Windows, select a cell and press Ctrl+K. Choose…
- Can You Import Excel and CSV Files Into QuickBooks?Yes. QuickBooks can import Excel and CSV files for certain kinds of data, but the accepted format depends…
- Excel Shortcut Codes: Essential Keys and How They WorkExcel shortcut codes usually means keyboard shortcuts: press a key or combination of keys to run a command…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.