To insert an image in an Excel VBA UserForm, open the form in the Visual Basic Editor, add an Image control from the Toolbox, then set its Picture property. To load a picture when the form opens or when a user clicks a button, assign the result of VBA’s LoadPicture function to the control’s Picture property.
What the UserForm Image control does
The Image control displays a picture inside a VBA form. It is separate from an image placed on a worksheet: it belongs to the form’s layout and appears while the form is displayed. Common uses include showing a company logo, a product thumbnail, an instruction graphic, or a picture associated with a selected record.
The control is designed to display an image, not to edit it. It does not provide the full set of cropping, drawing, or formatting tools found in a dedicated image editor. You can set its size and display behavior, and you can change which picture it shows through its properties or VBA code.
These instructions target Excel for Microsoft 365 on Windows. Excel for the web does not run VBA macros or display VBA UserForms. Excel for Mac includes VBA, but its editor and file-picker experience differ, and Windows-specific paths such as C:\Pictures\logo.jpg will not work unchanged on a Mac.
Add a picture at design time
Use the design-time method when the form should always display the same picture. The picture is assigned while you build the form, so no code is needed to load it when the form opens.
- In Excel, open the Visual Basic Editor with Alt+F11. On a Mac, the shortcut may depend on the keyboard and system settings; you can open the editor from Excel’s Developer tab instead.
- In the editor, choose Insert > UserForm, or select an existing form in the Project Explorer.
- If the Toolbox is not visible, choose View > Toolbox.
- Select the Image control in the Toolbox, then drag on the form to draw the area where the picture should appear.
- Select the new control. In the Properties window, find Picture, click its value, and use the browse button to choose an image file.
- Set the control’s Name property to a useful name, such as
imgLogo, and adjust PictureSizeMode to control how the image fits.
If the Toolbox control is not obvious, pause the pointer over its icons to see their names. The Image control is not the same as the Label control, which can display text and may have a picture-related property in some contexts. For a picture that should occupy a defined area and use image sizing options, choose Image.
Load an image with VBA at runtime
Runtime loading is useful when the picture changes according to a record, user choice, or file location. For example, put an Image control named imgLogo on the form, then place this event procedure in that form’s code module. Replace the sample path with the actual path to an image available on the computer running the workbook.
Private Sub UserForm_Initialize()
' Load the form's fixed logo when the form opens.
Me.imgLogo.Picture = LoadPicture("C:\Pictures\logo.jpg")
Me.imgLogo.PictureSizeMode = fmPictureSizeModeZoom
End Sub
The control name in the code must match the Image control’s Name property. The UserForm_Initialize event runs as the form is initialized, before it is displayed. If the file cannot be found or read, the assignment can fail, so check the path and file access when adapting the example.
For a user-selected file, place a CommandButton named cmdChoosePicture on the form and use this code in its click event. The dialog filter lists typical picture formats; actual formats accepted by LoadPicture can depend on the image format and Office environment.
Private Sub cmdChoosePicture_Click()
Dim selectedFile As Variant
' Ask the user to choose an image file.
selectedFile = Application.GetOpenFilename( _
"Image Files (*.bmp;*.gif;*.jpg;*.jpeg;*.ico)," & _
"*.bmp;*.gif;*.jpg;*.jpeg;*.ico")
' GetOpenFilename returns False if the user cancels.
If VarType(selectedFile) = vbBoolean Then Exit Sub
Me.imgLogo.Picture = LoadPicture(CStr(selectedFile))
Me.imgLogo.PictureSizeMode = fmPictureSizeModeZoom
End Sub
Save a copy of the workbook before running or changing a macro. VBA actions cannot be reversed with Ctrl+Z. The code above changes the form’s displayed picture; it does not insert the chosen file into a worksheet or permanently package an external file alongside the workbook.
Fit, stretch, or crop the picture
The PictureSizeMode property determines how a picture is displayed within the Image control’s boundary. Set it in the Properties window or in code. The available modes include:
- Clip (
fmPictureSizeModeClip): displays the picture at its original dimensions and clips any part that extends beyond the control. This can hide edges if the control is smaller than the picture. - Stretch (
fmPictureSizeModeStretch): resizes the picture to fill the control. It uses the whole area, but can distort the picture if the control and image have different proportions. - Zoom (
fmPictureSizeModeZoom): scales the picture to fit while preserving its proportions. It avoids distortion, though empty space can remain on two sides.
For logos, portraits, and product pictures, Zoom is often a sensible starting point because it preserves the original shape. If the image appears too small, adjust the control’s width and height or use an image with proportions closer to the control. Stretch may suit a background texture, but it is usually a poor choice for faces or logos.
Do not confuse the Image control’s boundary with the picture’s original dimensions. Resizing the control does not edit the source file. If you need a precisely cropped or compressed image, prepare it with an image editor before loading it into the form.
Choose a reliable image location
A path that works on your computer may not exist on another person’s computer. A path such as C:\Users\Alex\Desktop\logo.jpg is specific to one Windows account, while a mapped network drive may not be available to every user. If you use a fixed external image, decide where it will be stored and document that requirement.
Practical approaches include:
- Use a shared folder that all intended users can access, if network access is dependable.
- Let users browse for a picture, as in the example above, when the file varies by user.
- Keep a stable image path relative to the workbook only if your code deliberately builds and checks that path; VBA does not automatically make an arbitrary external image portable.
- For a small, fixed graphic, assign the picture at design time and test the saved form after closing and reopening the workbook.
For a workbook that must travel as one file, an external path is a portability risk. Design-time pictures are stored with the form in the workbook, but test the workbook in the environment where it will be used. For pictures selected at runtime, the workbook does not automatically embed the chosen image just because the Image control displays it.
Image control versus a worksheet picture
Use a UserForm Image control when the picture is part of a dialog or data-entry screen. For example, a form could show a product image beside fields for product code and price. Use a worksheet picture when the image should remain visible on the sheet, be printed with it, or be arranged alongside cells.
These are different tasks. Assigning Me.imgLogo.Picture changes what a form control displays; it does not create a picture on the active worksheet. Conversely, inserting an image on a worksheet does not automatically make it appear in a UserForm. Choose the destination first, then use the corresponding form control or worksheet image tools.
If the goal is a form background rather than a separate image area, consider whether the graphic should be a background or an Image control. A separate control is easier to size and position independently, while a background is intended to sit behind other controls. Keep text readable and ensure the image does not obscure buttons or fields.
Common problems and fixes
- The form opens with no picture: confirm that the code is in the correct UserForm module, the event name is spelled correctly, and the control’s Name property matches the code. For design-time pictures, check the Picture property in the Properties window.
- LoadPicture reports an error: verify the complete path, spelling, file extension, and permissions. Try opening the file outside Excel. A valid-looking extension does not guarantee that the file contains a supported picture format.
- The picture looks distorted: change PictureSizeMode from Stretch to Zoom, or resize the control to better match the picture’s aspect ratio.
- Only part of the image appears: check whether PictureSizeMode is set to Clip and whether the picture is larger than the control.
- The image works on one computer but not another: the other computer may not have the external file at the same path, or may not have permission to access it. Use a stable shared location or let the user select the image.
- The macro does not run: confirm that the workbook is saved in a macro-enabled format such as
.xlsmand that its macros are permitted by the organization’s security settings. Do not enable macros in files from untrusted sources.
When diagnosing a problem, test with a simple picture file and a short local path first. That separates a bad path or access issue from a control-sizing problem. Once the basic example works, restore the intended file location and layout.
Compatibility and safe use
VBA UserForms are for desktop Excel, not Excel for the web. On Windows, the examples use the Visual Basic Editor, the UserForm Toolbox, and Excel’s Application.GetOpenFilename method. Excel for Mac supports VBA, but interface details, file paths, and some platform-specific behavior differ. Use Mac-style file locations on a Mac and test the workbook there; do not assume that a Windows path or every Windows workflow will transfer unchanged.
Only run macros from files you trust. A macro that displays a picture is not inherently dangerous, but a workbook’s VBA project can contain other code. If a workbook is shared, explain any required image folder and avoid asking users to enable macros without a clear reason. Keep a backup before changing VBA or testing code that also edits workbook data.
Frequently Asked Questions
Can I insert a picture directly into a VBA UserForm?
Yes. Add an Image control from the Toolbox and assign its Picture property in the Properties window. You can also load a picture at runtime with LoadPicture.
How do I make a picture fit the whole UserForm Image control?
Set PictureSizeMode to fmPictureSizeModeStretch to fill the control, accepting that proportions may become distorted. Use fmPictureSizeModeZoom to preserve proportions, with possible blank space.
Can a UserForm image change when I choose a different record?
Yes. Store or derive the image path for each record, then assign the matching file with LoadPicture when the selection changes. Make sure the path exists and handle missing files so the form does not fail unexpectedly.
Does the workbook include an image loaded from a file path?
Not automatically. Runtime loading displays an external file in the control but does not, by itself, embed that file in the workbook. A picture assigned to the form at design time is saved as part of the form, but test the saved workbook on the intended computers.
Can I show a PNG in a VBA UserForm?
Support can vary by Office and VBA environment, so do not assume every image type will load through LoadPicture. If a PNG fails, try a commonly supported alternative such as BMP or JPG, or convert the image and test it in the target version of Excel.
Related
- How to Strikethrough Numbers in Excel: Steps and Tips
- How to Make Serial Numbers in Excel: 4 Easy Methods
- Color Certain Words in Excel: A Step-by-Step Guide
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Now: What Still Works and What Doesn’t in 2026Yes—Excel VBA is still supported in the desktop versions of Excel for Microsoft 365, and it remains useful…
- Excel VBA IsError: Check for Worksheet Errors in CodeIn Excel VBA, IsError(expression) returns True when an expression evaluates to an error value and False otherwise. Use…
- Excel VBA Delete Row: Methods, Examples, and Best PracticesTo delete a worksheet row with Excel VBA, reference the worksheet and call its Rows collection’s Delete method—for…
- Outlook VBA: Pull Email Data into ExcelTo pull email data from Outlook into Excel, run a VBA macro in Excel that connects to classic…
- Delete the Last Row in Excel VBA SafelyTo delete the last data row of an Excel table, use the table’s ListRows collection: tbl.ListRows(tbl.ListRows.Count).Delete. For a…
- VBA Error Handling for Multiple Errors in One MacroVBA handles runtime errors one at a time: use On Error GoTo to route an unexpected failure to…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.