To add an image to an Excel VBA UserForm, open the form in the Visual Basic Editor, place an Image control from the Toolbox, and set its Picture property in the Properties window. For a picture that changes at run time, assign a file with VBA’s LoadPicture function; then choose whether the image should be clipped, stretched, or scaled to fit.
What an Excel UserForm image is
A UserForm is a custom VBA dialog box that can collect information or present controls while a workbook is open. Its Image control displays a picture inside the form. Common uses include a company logo, a product photo beside a product selector, an instruction diagram, or a preview that changes when someone makes a choice.
An Image control is different from a picture placed on a worksheet. It belongs to the form’s design and layout, so it appears when the form appears. A worksheet picture is a shape on a sheet and does not automatically become part of a UserForm. The control also differs from a Label: a Label is primarily for text, while an Image control is intended to show a picture.
UserForms and VBA macros are desktop Excel features. Excel for the web does not run VBA UserForms, so a form that depends on one will not work there. This guidance is for Excel for Microsoft 365 on Windows.
Add a picture in the UserForm designer
For a picture that will stay the same, setting it in the designer is usually the simplest approach. The Visual Basic Editor is available from Developer > Visual Basic. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon and select Developer. In the editor, insert or open a UserForm, then use the Toolbox to add an Image control.
- Select the Image control on the form and drag its sizing handles to make a display area.
- With the control selected, press F4 to show the Properties window if it is not already visible.
- Find the Picture property and use its browse button to choose an image file.
- Set the PictureSizeMode property to determine how the image fits the control.
- Save the workbook as a macro-enabled Excel workbook (.xlsm) if it contains VBA.
Use the Properties window to give the control a meaningful name, such as imgProduct, rather than relying on a generated name such as Image1. A descriptive name makes later code easier to read. Design-time pictures are stored with the form in the workbook, which is convenient when the picture is fixed and the workbook needs to travel as one file.
Choose how the image fits
The control’s PictureSizeMode setting governs how its picture is displayed. The setting matters because an image can have a different aspect ratio from the rectangle drawn on the form.
- Clip: Displays the picture at its original size and shows only the portion that fits inside the control. The picture is not resized to fill the rectangle.
- Stretch: Resizes the picture to fill the whole control. This can make a logo, face, or product look unnaturally wide or tall if the proportions differ.
- Zoom: Scales the picture proportionally to fit within the control. It preserves the picture’s proportions, though empty space can remain along one side or above and below it.
For photographs, logos, and most product images, Zoom is generally the safest starting choice because it avoids distortion. Stretch can be appropriate for a texture or background where filling the whole rectangle matters more than preserving exact proportions. Clip is useful when the control is intended to show a fixed-size part of a larger image, but it can surprise users if they expect the whole picture to appear.
Size the control with the form layout in mind: leave room for buttons and text, avoid making a small picture so large that it looks blurry, and preview the form at the size users will see. If the picture looks cropped, check both the control’s dimensions and its PictureSizeMode before editing the source image.
Load a picture from a file with VBA
Dynamic images are useful when a form should display a selected item’s photo or when an image file may be updated without redesigning the form. Add an Image control and, if useful, a Label for a message. The following example assumes the form has an Image control named imgLogo and a Label named lblStatus. It looks for images\logo.jpg in a folder beside the workbook.
Private Sub UserForm_Initialize()
Dim imagePath As String
' Build a path to the image folder beside this workbook.
imagePath = ThisWorkbook.Path & Application.PathSeparator & _
"images" & Application.PathSeparator & "logo.jpg"
' Load the picture only when the file exists.
If Len(Dir$(imagePath)) > 0 Then
Me.imgLogo.Picture = LoadPicture(imagePath)
Me.imgLogo.PictureSizeMode = fmPictureSizeModeZoom
Else
Me.lblStatus.Caption = "Image file not found."
End If
End Sub
In this example, the workbook should be saved in a folder before the form is shown, with a subfolder named images and the file logo.jpg inside it. ThisWorkbook.Path refers to the folder containing the workbook, while Application.PathSeparator supplies the separator used by the operating system. A relative folder layout is usually easier to move than a path tied to one person’s Windows profile.
Change the control name, folder, and file name to match the workbook. If your form uses different controls, update those references too. The check with Dir$ prevents an immediate file-not-found error, but it does not repair a wrong path; the status message gives the user a clue that the expected file is missing. Save a copy of the workbook before running or changing a macro. VBA changes cannot be undone with Ctrl+Z.
Supported image files and preparation
VBA’s standard LoadPicture function handles common formats such as BMP, GIF, JPG/JPEG, ICO, WMF, and EMF. PNG is a frequent source of confusion: standard VBA LoadPicture does not reliably load PNG files. If a PNG fails, convert it to a supported format such as JPG or BMP, or use a different image-loading approach that has been deliberately added to the project.
Choose a format based on the picture. JPG is often suitable for photographs; BMP can be useful for simple graphics but can produce large files; GIF is suited to limited-colour graphics and does not make a UserForm Image control into an animated-image player. A vector-style EMF or WMF may be useful for certain diagrams, although appearance can vary with the source and scaling. Check the actual result in the form rather than assuming that every file extension will display identically.
Crop or resize a very large source image before embedding or loading it. A picture several thousand pixels wide may add unnecessary file weight when it will appear in a small dialog. Keep a clear source copy, and use a sensible display resolution so that text or fine detail remains readable.
Common problems and how to diagnose them
- The image is blank: Confirm that the Image control has a Picture assigned, the file path is correct, and the file exists. Check the extension and try a supported format such as JPG. A path that works on the author’s computer may not exist on another computer.
- The picture is distorted: Change PictureSizeMode from Stretch to Zoom, or adjust the control’s shape to better match the image’s proportions.
- The image is cropped: Check whether the setting is Clip. Zoom shows the whole picture within the control, while Clip can show only the part that fits.
- The workbook works locally but not after sharing: A hard-coded path such as a user-specific Documents folder is not portable. Store the image beside the workbook or embed a fixed picture at design time, and include any required image folder when distributing the file.
- The form says the image is missing after moving the workbook: Check that the relative folder structure moved with it. If the workbook was never saved, its path may also be empty, so save it before relying on
ThisWorkbook.Path. - The picture seems too large or the workbook grows: Reduce the source image’s dimensions or use an appropriate compressed format. Consider whether a large image is necessary for the form’s purpose.
When diagnosing a blank picture, test the file path independently and verify the exact file name, including its extension. Also check whether the code runs at the time the form is shown: code in UserForm_Initialize runs as the form is initialized, but code in a button event runs only after that button is clicked. Keeping loading logic in one clear place makes it easier to identify when the assignment should happen.
Embedded pictures versus external files
A design-time picture is convenient because the form and its fixed image are carried in the workbook together. It avoids a separate image folder going missing and is a good fit for a logo or an instruction graphic that rarely changes. The trade-off is that changing the picture generally means editing the form or replacing its assigned picture.
An external file is more flexible: the form can select a different file based on a record, and an administrator can update a photo without rebuilding the form. But the workbook then depends on the file being available at the expected location and in a format VBA can load. A shared-drive path may work in an organization but fail for someone without access; a relative folder beside the workbook is often more portable for a package that is copied as a unit.
There is no general need to use an external file just because the picture is large, or to embed every picture when the displayed image changes by record. Choose based on how often the image changes and how the workbook will be distributed. If many records each have a photo, consider whether a UserForm is the right interface and whether the image files can be managed as part of a documented folder structure.
Accessibility and practical design
A picture should support the task rather than carry essential information by itself. If a product image identifies the selected item, show the item’s name or code in text as well. Provide a nearby Label with a useful status when no picture is available, and do not rely on colour alone to distinguish image states. Test the form with the keyboard and make sure users can still complete the task if a picture does not load.
Keep important text out of the image when possible. Text baked into a picture may be difficult to read when scaled and cannot be corrected as easily as a normal Label. Use a clear, consistent size for pictures in repeated records, and leave enough space around controls so that the image does not crowd the form’s fields or buttons.
Alternatives and platform limits
If the goal is simply to show a static graphic alongside worksheet data, a picture placed directly on a worksheet may be simpler than a VBA form. If the workbook must work in Excel for the web, design around web-compatible worksheet features rather than a VBA UserForm, because browser Excel does not execute VBA. For a form that must run on both Windows and Mac, verify the controls, image formats, and VBA behavior in the target Mac version instead of assuming that a Windows-specific path or component will transfer unchanged.
Excel for Mac has differences in VBA and control support, and Windows-specific ActiveX techniques should not be treated as cross-platform solutions. The Image control and file-loading behavior should be checked in the actual Mac environment if Mac users are a requirement. Avoid adding external libraries or platform-specific components unless their installation and support are part of the deployment plan.
Frequently Asked Questions
How do I insert a picture into an Excel UserForm?
Open the form in the Visual Basic Editor, add an Image control from the Toolbox, select the control, and assign a file through the Picture property in the Properties window. Set PictureSizeMode to control how it fits.
Can an Excel UserForm display a PNG image?
Standard VBA LoadPicture does not reliably support PNG. Convert the picture to a supported format such as JPG or BMP, or choose a separately implemented method that explicitly supports PNG.
How can I make a UserForm image keep its proportions?
Set the Image control’s PictureSizeMode to Zoom. It scales the picture proportionally to fit within the control, though it may leave unused space on one or more sides.
Why does my UserForm image disappear on another computer?
If the form loads an external file, the other computer must have that file at the expected path and have access to it. Use a portable folder arrangement and include the image files, or set a fixed picture in the form designer.
Do VBA UserForm images work in Excel for the web?
No. Excel for the web does not run VBA UserForms. Use a worksheet-based design or another interface suitable for browser use if web access is required.
Related
- Power Query Split Cell Into Rows: Steps and Examples
- Power Query Editor: How to Split Text into Multiple Columns
- Power Query Union Tables: How to Append Queries
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel Macro Workbook: What It Is and How to Use OneAn Excel macro workbook is an Excel file that can store and run macros—sets of instructions that automate…
- Access VBA InputBox Syntax and Practical Examples ExplainedIn Access VBA, use InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context]) to show a…
- How to Set Up a Macro on a SteelSeries Mouse with GGTo put a macro on a SteelSeries mouse, install SteelSeries GG, open Engine, select your mouse, assign a…
- VBA Sort Cells in Excel: Code, Options, and Common FixesTo sort cells with VBA in Excel, sort the entire data range by a key column—not just one…
- VBA Error Handler: How On Error Works and When to Use ItIn VBA, an error handler is code that responds when a statement fails while a procedure is running.…
- Macro Recorder App: What It Does and How to ChooseA macro recorder app captures a sequence of actions so you can repeat them automatically; in desktop Excel…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.