Excel VBA UserForm Image: Add, Load, and Troubleshoot

VBA & macros · Updated November 3, 2026

Excel VBA UserForm Image: Add, Load, and Troubleshoot

An Excel VBA UserForm displays a picture with the Microsoft Forms Image control: add the control in the UserForm designer, set its Picture property, or load a picture at runtime with LoadPicture. Use the control’s PictureSizeMode setting to fit the image into the space you have without accidentally stretching it.

What an Image control does

An Image control is a visual element on a VBA UserForm. It can show a logo, product photograph, instruction graphic, or other picture alongside the form’s text boxes, labels, and buttons. The control is intended to display an image; it is not an image editor, and it does not provide the same interaction as a button or a web browser.

In Microsoft 365 for Windows, UserForms are created in the Visual Basic Editor (VBE). The form and its controls are part of the workbook’s VBA project. A picture assigned in the designer is generally saved with the form, while a picture loaded from a file at runtime depends on that file still being available at the path the code uses.

Excel for the web does not run VBA macros or display VBA UserForms. Excel for Mac has VBA support, but UserForm behavior, controls, file paths, and keyboard shortcuts can differ from Windows. If a workbook must work across both platforms, test the form and its image-loading method in each desktop version you intend to support.

Add an Image control to a UserForm

  1. In desktop Excel for Windows, open the workbook and press Alt+F11 to open the VBE. On a Mac, use Developer > Visual Basic or the keyboard shortcut available for your keyboard; some keyboards require the Fn key.
  2. In the VBE, choose Insert > UserForm. If the Toolbox is not visible, choose View > Toolbox.
  3. Click the Image control in the Toolbox, then drag on the UserForm to draw the area where the picture should appear.
  4. Select the new control and open the Properties window, usually with F4. Change its (Name) property to a descriptive name such as imgLogo.
  5. To store a picture in the form design, select the Picture property and use its browse button to choose an image file. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if it contains VBA.

A UserForm can contain more than one Image control. Giving each a meaningful name makes later code easier to read than leaving controls named Image1, Image2, and so on. For example, imgProduct and imgStatus describe their purpose without requiring someone to inspect the form layout.

Choose how the image fits

The PictureSizeMode property determines how the picture is displayed inside the control’s rectangular boundary. It matters whenever the image and the control have different proportions or dimensions. Set it in the Properties window at design time, or assign an appropriate setting in VBA.

  • Clip: Displays the image at its original size and clips parts that do not fit in the control. This can hide edges if the control is too small.
  • Stretch: Resizes the image to fill the entire control. It uses the full area, but can make people, logos, and other objects look unnaturally wide or tall.
  • Zoom: Scales the picture to fit while preserving its aspect ratio. Depending on the image’s shape, unused space can remain along one side or above and below it. This is often a good choice for photos and logos.
  • AutoSize: Sizes the control to the picture rather than forcing the picture into a fixed-size box. This can be useful for a small graphic but may make a carefully arranged form larger than intended.

For a logo in a fixed rectangle, Zoom is usually a sensible starting point. For a background-like graphic that must fill every pixel, Stretch may be acceptable if distortion is not noticeable. Preview the actual image at the form’s intended size: a setting that looks right for a square icon may not suit a wide banner.

Load a picture when the form opens

Use LoadPicture when the picture should be chosen or updated at runtime, or when you want the form to load a file from a known location. The following code belongs in the UserForm’s code module. It assumes the picture is named logo.jpg and is in the same folder as the workbook.

Option Explicit

Private Sub UserForm_Initialize()
    Dim imagePath As String

    ' Build a path beside the workbook.
    imagePath = ThisWorkbook.Path & Application.PathSeparator & "logo.jpg"

    ' Report a missing file instead of failing during form startup.
    If Len(Dir$(imagePath)) = 0 Then
        MsgBox "Image file not found: " & imagePath, vbExclamation
        Exit Sub
    End If

    ' Load the picture and preserve its proportions in the control.
    Set Me.imgLogo.Picture = LoadPicture(imagePath)
    Me.imgLogo.PictureSizeMode = fmPictureSizeModeZoom
End Sub

The code expects the Image control to be named imgLogo. Change the filename or control name to match your workbook. If the workbook has not been saved, ThisWorkbook.Path can be empty, so save it before relying on a file stored beside it. Application.PathSeparator supplies the separator used by the current Excel environment, which is safer than hard-coding a Windows backslash for a workbook that may be opened on a Mac.

In this example, LoadPicture reads from a file path. It does not place the external image inside the workbook merely because the form displays it. If the file is moved, renamed, or unavailable on another user’s computer, the form cannot load it from that old location. A design-time picture or a deliberately managed shared folder may be more suitable when users need a self-contained or centrally maintained image.

Image formats, paths, and portability

The classic VBA LoadPicture function is commonly used with formats such as BMP, GIF, JPG/JPEG, ICO, EMF, and WMF. PNG is a frequent source of confusion: support can depend on the control and Office environment, so do not assume that a PNG which works in another part of Office will load reliably through LoadPicture in every UserForm. If compatibility is important, use a format supported by the target environment and test the actual workbook.

Paths also cause problems when a workbook is shared. A path such as C:\Users\Ava\Desktop\logo.jpg points to one user’s computer, not to a universal location. A relative path based on ThisWorkbook.Path can work when the image travels with the workbook in the same folder, but it still requires the image file to be distributed. A network path requires access to that network location, and a cloud-synced folder may have different local paths for different people.

For a small, stable logo, assigning the picture in the designer avoids a separate-file lookup when the form opens. For a large collection of changing images, loading files at runtime can be easier to maintain, but plan how the files will be installed, named, and accessed. Avoid assuming that an internet URL can be passed to LoadPicture as if it were a local filename; downloading or retrieving remote content requires a separate approach.

Common display and loading problems

  • The control is blank: Check that the form’s code uses the control’s actual (Name), the file path is correct, and the file exists when the form opens. A missing file can be caused by an unsaved workbook with an empty folder path.
  • The picture is distorted: Change PictureSizeMode from Stretch to Zoom, or resize the control to better match the image’s shape.
  • The image is cropped: Check whether Clip is selected and whether the control is smaller than the picture. Zoom can show the whole picture while leaving empty space.
  • The image works on one computer only: Replace a user-specific file path with a shared, properly distributed location or store a suitable picture in the form design.
  • The file type will not load: Test with a known compatible format such as JPG or BMP. Do not treat PNG support through LoadPicture as universal.
  • The macro does not run: Confirm the workbook is saved as .xlsm and that the organization’s macro security settings permit its VBA project to run. Do not weaken security settings just to make an unfamiliar workbook work.

When diagnosing a blank control, distinguish a display setting problem from a loading problem. If a picture assigned in the designer appears but a runtime picture does not, the control itself is probably present; focus on the filename, path, file access, and format. If neither picture appears, check the control’s size, visibility, and position on the UserForm.

Design, accessibility, and workbook safety

Keep the picture useful rather than decorative when space is limited. A logo can identify a form, while an instructional image can clarify a step that would otherwise need a long explanation. Provide nearby text for information conveyed only by an image; a picture of a warning, for example, should not be the only indication that an action is risky. UserForms are not web pages with automatic alternative-text behavior, so make essential information available through labels or other controls too.

Large image files can increase workbook size and may make a form slower to open or redraw. Resize or compress a picture before adding it if its original resolution is far beyond what the form displays. Keep the image’s proportions intact unless distortion is intentional, and check the form at the display scaling used by its intended audience.

Before running or distributing VBA that changes a workbook, save a separate copy. Macros cannot be undone with Ctrl+Z, and the VBA editor does not provide the usual worksheet undo history for macro actions. Only enable macros in files from sources you trust, and make sure external image paths do not expose information or rely on locations that recipients cannot access.

Alternatives to a UserForm Image control

If the picture belongs on a worksheet rather than inside a dialog, insert it directly on the worksheet using Insert > Pictures. That is simpler when users only need to view or move the image and do not need a VBA form. A worksheet picture can also be placed near data and instructions without opening a separate window.

If users need a clickable action, use a CommandButton and give it a clear caption rather than relying on an Image control to behave like a button. If a form must display many pictures or advanced image interactions, a standard VBA UserForm may be too limited; consider whether a worksheet interface or another application is a better fit. Excel for the web cannot run VBA UserForms, so a web-based workflow needs an alternative that works without desktop macros.

Frequently Asked Questions

How do I insert an image into an Excel VBA UserForm?
Open the UserForm in the VBE, show the Toolbox, select Image, and draw the control. Set its Picture property in the Properties window to select a design-time picture, or use LoadPicture in the form’s code to load a file at runtime.

How do I make a UserForm image fit without distortion?
Set PictureSizeMode to Zoom. It preserves the image’s proportions and fits it within the control, though it may leave blank space. Stretch fills the box but can distort the picture.

Can I use a PNG image with VBA LoadPicture?
Do not assume PNG will work consistently with the classic UserForm Image control and LoadPicture. Support can vary by environment. Test on the target Excel versions or use a commonly supported format such as JPG or BMP.

Why does my UserForm image disappear on another computer?
If the code loads an external file, the other computer must be able to access that same path and file. A personal desktop path will not transfer automatically. Distribute the file with the workbook using a planned path, or assign a suitable image in the form designer.

Can an Excel UserForm image work in Excel for the web?
No. Excel for the web does not run VBA macros or open VBA UserForms. Use desktop Excel for a VBA form, or redesign the workflow for a web-compatible tool if browser access is required.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.