Use an Excel chart on a worksheet as the graph source, export it as a JPEG, then load that image into an Image control on a UserForm. In Excel for Microsoft 365 on Windows, name the chart object chtSales, add an Image control named imgGraph to the form, and use the VBA below to display and refresh the graph.
How the UserForm graph approach works
An Excel UserForm does not provide a built-in control that hosts a normal, fully interactive worksheet chart. A practical solution is to keep the chart on a worksheet, export its current appearance to an image file, and show that image in the form. The image is a snapshot: it can look like the chart, but users cannot click its legend, select data points, or edit the chart from the UserForm.
This arrangement is useful for dashboards, data-entry forms, and summary screens where a graph should appear beside form fields. The worksheet chart remains the source of truth, so its series, formatting, and data links are managed with Excel’s usual chart tools. When the underlying data changes, the macro exports the chart again and replaces the displayed picture.
Prepare the worksheet chart and UserForm
First create a regular Excel chart from the data you want to show. For example, select a date column and a sales column, then choose Insert > Recommended Charts or select a chart type from the Insert tab. Put the chart on a worksheet named Dashboard. Select the chart and use the Name Box to the left of the formula bar to assign the chart object the name chtSales. This is the chart object name, not the chart title.
In the Visual Basic Editor, insert a UserForm and add an Image control. Set the Image control’s (Name) property to imgGraph. Enlarge it to the area where the graph should appear. Set its PictureSizeMode property to 3 - fmPictureSizeModeZoom if you want the full image to fit without distortion; the control may leave unused space at one edge. Use Stretch only when filling every pixel matters more than preserving the graph’s proportions.
- Open the Visual Basic Editor with Alt+F11 on Windows. On Mac, use Tools > Macro > Visual Basic Editor if that menu is available in your Excel build.
- In the editor, choose Insert > UserForm, then use the Toolbox to add an Image control.
- In the Properties window, set the form and image names as needed, especially the image name
imgGraph. - Confirm the worksheet is named
Dashboardand the chart object is namedchtSales, or edit the corresponding names in the code.
VBA code to load the graph
Place this code in the UserForm’s code module. It exports the chart as a JPEG in the Windows temporary folder and loads the exported file into the Image control when the form opens. A timestamped file name avoids reusing a previous image file when the graph is refreshed quickly.
Private Sub UserForm_Initialize()
' Display the worksheet chart when the form opens.
RefreshGraph
End Sub
Private Sub RefreshGraph()
Dim ws As Worksheet
Dim co As ChartObject
Dim imagePath As String
Dim chartExported As Boolean
On Error GoTo ErrorHandler
Set ws = ThisWorkbook.Worksheets("Dashboard")
Set co = ws.ChartObjects("chtSales")
' Use a new temporary file name so the picture is not stale.
imagePath = Environ$("TEMP") & "\sales-graph-" & _
Format$(Now, "yyyymmdd-hhnnss") & "-" & _
Format$(CLng(Timer * 1000), "00000000") & ".jpg"
chartExported = co.Chart.Export(Filename:=imagePath, FilterName:="JPG")
If Not chartExported Then
MsgBox "Excel could not export the chart image.", vbExclamation
Exit Sub
End If
Me.imgGraph.PictureSizeMode = fmPictureSizeModeZoom
Me.imgGraph.Picture = LoadPicture(imagePath)
Exit Sub
ErrorHandler:
MsgBox "The graph could not be displayed: " & Err.Description, vbExclamation
End Sub
The code expects a chart object on the stated worksheet and an Image control on the form with the exact names shown. It uses Excel’s chart export and the VBA LoadPicture function; JPEG is chosen because it is a widely supported image format for this type of control. If the form opens but the picture is blank, check that the chart and control names match exactly and that the chart can be exported on your computer.
Refresh the picture after data changes
The initialization event runs when the form is opened, but it does not automatically run every time a worksheet cell changes. If a user edits values while the form remains open, call RefreshGraph again after the edit or provide a refresh button. To add a button, put a CommandButton on the form, name it cmdRefresh, and add this event procedure to the same UserForm module:
Private Sub cmdRefresh_Click()
' Re-export the chart and replace the displayed picture.
RefreshGraph
End Sub
Alternatively, call the refresh routine from the event that saves or recalculates the form’s data. For example, if a button writes new values to the worksheet, place RefreshGraph after those values have been written. The chart must be linked to the updated cells; refreshing the image cannot correct a chart whose data source points to the wrong range. If formulas feed the chart, calculate the sheet before exporting when calculation is set to manual.
The sample creates a new file in the temporary folder for each refresh. This avoids potential stale-picture behavior from repeatedly loading one path, but it can leave temporary JPEGs behind. If the form refreshes very frequently, add a cleanup strategy appropriate to your application, and do not delete an image file before the control has finished loading it.
Choose a suitable chart size and appearance
The image displays the chart’s exported dimensions, so design the worksheet chart with the UserForm space in mind. Make chart titles and axis labels large enough to read when scaled down. A chart with many categories may be legible on a worksheet but crowded inside a small form. Consider filtering the chart to a shorter date range, reducing unnecessary gridlines, or increasing the Image control’s dimensions.
- Zoom: preserves proportions and shows the full graph, though blank margins can appear.
- Stretch: fills the control but can make circles, text, and other chart elements look distorted.
- Crop or clip: can make the graph appear larger, but may hide titles, labels, or legends near the edges.
Keep a clear chart title and use contrasting series colors. Remember that the display is a raster image rather than a live chart object. Small text may soften when enlarged, and image quality depends on the exported chart dimensions. Adjust the chart’s size on the worksheet and the form’s Image control together rather than assuming that a larger UserForm will automatically produce a sharper image.
Common problems and fixes
“Subscript out of range” or an object-not-found error: The worksheet or chart object name does not match the code. Check the sheet tab name and the chart’s object name; a chart title such as “Monthly Sales” is not automatically its object name. Also make sure the chart is embedded on the worksheet, not a separate chart sheet, because the sample uses Worksheet.ChartObjects.
“Could not export” or no picture appears: Confirm that the chart exists and that the export path is writable. The sample uses the Windows TEMP folder and JPG export. If the graphics filter is unavailable in a particular installation, try another supported export format and verify that the Image control can load that format. Do not simply change the file extension; the export filter and extension must match.
The picture does not update: Confirm that the refresh procedure runs after the source data changes and that the chart’s series refer to those cells. If a chart is driven by formulas, check calculation mode and recalculate first. The form’s image is only refreshed when the VBA code exports and loads a new file; changing a cell by itself does not update an already loaded picture.
Compile error on the sizing constant: Check that the code is in an Excel UserForm module and that the control is an MSForms Image control, not a worksheet image or another control type. You can also set PictureSizeMode in the Properties window instead of assigning the constant in code.
Alternatives and platform limitations
If users need to interact with the graph, keep the chart on a worksheet and show or activate that worksheet rather than presenting a static image. Another option is to build a custom visualization from controls, but that requires more code to draw axes, labels, and data points and to keep them synchronized. For a compact status display, the exported-image method is generally simpler; for chart editing or point-level interaction, a worksheet chart is the more appropriate choice.
This example targets desktop Excel for Microsoft 365 on Windows. Excel for the web does not run VBA macros or display VBA UserForms, so the form cannot be used there. Excel for Mac has VBA support, but control behavior, available graphics filters, and file paths can differ across versions. The Windows temporary-folder path and JPG export should therefore be checked on the target Mac build rather than assumed to work unchanged. Avoid Windows API calls in a cross-platform form unless you provide separate platform-specific code.
Save and run the macro safely
Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) so its VBA project is retained. Enable macros only for workbooks you trust, and make a copy of the workbook before running a macro that modifies data or files. VBA actions cannot be undone with Ctrl+Z, even when the macro appears to make only a small change. This sample exports an image and changes the form’s displayed picture; it does not intentionally edit worksheet values, but a backup is still sensible while adapting code.
On Windows, Alt+F11 opens the Visual Basic Editor and F5 runs the active procedure when appropriate. On Mac, the editor and shortcut availability differ by keyboard and Excel version; use the Tools menu if the shortcut does not work. To show the form from a worksheet button or another macro, call its default instance, for example UserForm1.Show, replacing the name with the actual form name. Keep the workbook open while the form uses its worksheet chart.
Frequently Asked Questions
Can I put a live Excel chart directly on a UserForm?
A standard UserForm Image control displays a picture, not a live Excel chart object. Exporting a worksheet chart to an image is a straightforward display method, but users cannot interact with the image as they can with the original chart.
Why does my UserForm show a blank graph?
Check that the chart is embedded on the named worksheet, the chart object and Image control names match the code, and chart export succeeds. Also verify the temporary folder is writable and that the selected image format is supported by the control.
How do I update the graph after changing cells?
Run the refresh routine after writing or recalculating the source data. A refresh button is a simple option. The graph changes only if its chart series are connected to the cells that were updated.
Can I use PNG instead of JPG?
Possibly, if the installed Excel graphics filter can export PNG and the UserForm Image control in the target environment can load it. JPG is used in the example for broad compatibility; match the export filter, file extension, and image loader support rather than changing only the suffix.
Will this work in Excel for the web?
No. Excel for the web does not run VBA macros or UserForms. Use desktop Excel for this VBA approach, or choose a web-compatible dashboard or chart display for browser users.
Related
- Data Validation Process: Steps, Checks, and Best Practices
- Data Validation Named Range in Excel: Setup and Fixes
- Data Validation Reference Table in Excel
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Resize: Change a Range’s Size with VBA CodeIn Excel VBA, use the Resize property to refer to a range with a different number of rows…
- Do Excel Macros Work in Google Sheets?No. Excel macros written in VBA do not run in Google Sheets, and converting an Excel workbook does…
- Macro Recorder for Mac OS X: Best Options and SetupFor a macro recorder on Mac OS X, use Automator’s “Watch Me Do” recording feature if your version…
- Move a Picture in an Excel UserForm with the MouseTo move a picture around an Excel UserForm with the mouse, handle the Image control’s MouseDown and MouseMove…
- Razer Macro Recorder: How to Record and Use MacrosIf by “Razor macro recorder” you mean Razer’s gaming peripherals, you can record and assign macros in Razer…
- Import CSV to Excel Using VBA: A Practical GuideTo import a CSV file into Excel with VBA, use Workbooks.OpenText to parse the file, then copy its…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.