Excel VBA Export Chart: Image, PDF, and Options

VBA & macros · Updated November 19, 2026

To export an embedded Excel chart with VBA as a PNG, call its Chart.Export method and specify a file name and image filter. For example, ChartObject.Chart.Export Filename:=filePath, FilterName:="PNG" saves the chart as an image; Excel VBA can also export a chart to PDF with Chart.ExportAsFixedFormat.

What VBA exports from a chart

Excel charts come in two main forms: an embedded chart positioned on a worksheet, and a chart sheet that occupies its own sheet tab. An embedded chart is represented by a ChartObject; its actual chart is the Chart inside it. A chart sheet is already a Chart. Knowing which type you have matters because the VBA reference to it differs, even though the export methods belong to the chart.

Exporting a chart creates a separate file, such as a PNG or PDF. It does not export the underlying worksheet data, formulas, or workbook, and it does not remove the chart from Excel. This is useful when a report needs a fixed visual for email, a document, or a presentation while the source workbook remains editable.

For a worksheet chart, use ChartObjects to identify the embedded object and then call its Chart.Export method. For a chart sheet, refer to the chart through the Charts collection. Avoid relying on ActiveChart in repeatable automation: it depends on what the user last selected and can point to the wrong chart or nothing at all.

Export an embedded chart as a PNG

This example exports the chart object named Chart 1 on a worksheet named Report. Change both names to match your workbook. The workbook must already have been saved to a local folder so the macro has a usable destination path.

Option Explicit

Sub ExportReportChartPNG()
    Dim ws As Worksheet
    Dim chartObject As ChartObject
    Dim filePath As String
    Dim exported As Boolean

    ' Find the worksheet and embedded chart by their object names.
    Set ws = ThisWorkbook.Worksheets("Report")
    Set chartObject = ws.ChartObjects("Chart 1")

    ' Put the PNG beside the saved workbook.
    If Len(ThisWorkbook.Path) = 0 Then
        MsgBox "Save the workbook before exporting the chart."
        Exit Sub
    End If

    filePath = ThisWorkbook.Path & Application.PathSeparator & "RevenueChart.png"
    exported = chartObject.Chart.Export(Filename:=filePath, FilterName:="PNG")

    If exported Then
        MsgBox "Chart exported to: " & filePath
    Else
        MsgBox "Excel did not export the chart."
    End If
End Sub

Before running any macro, save a copy of the workbook. VBA actions generally cannot be reversed with Ctrl+Z. To run this example in desktop Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, choose Insert > Module, paste the procedure, and run it with the cursor inside the procedure. On Mac, use Tools > Macro > Visual Basic Editor; the shortcut is commonly Option+F11, sometimes with Fn depending on the keyboard.

Choose an image format or PDF

For an image file, Chart.Export takes a file name and a filter name. PNG is a practical choice for charts containing text, lines, and solid colors. JPEG can suit photographic content, but its compression may soften fine chart labels or edges. The export formats available can depend on Excel and the installed graphics filters, so check the result in the software that will use it rather than assuming every filter is present.

Use PDF when the recipient needs a document-style file that can be printed or viewed without placing an image into another document. A chart can be exported directly as a fixed-format PDF:

Option Explicit

Sub ExportReportChartPDF()
    Dim ws As Worksheet
    Dim chartObject As ChartObject
    Dim filePath As String

    ' Refer to the embedded chart by its worksheet and object names.
    Set ws = ThisWorkbook.Worksheets("Report")
    Set chartObject = ws.ChartObjects("Chart 1")

    If Len(ThisWorkbook.Path) = 0 Then
        MsgBox "Save the workbook before exporting the chart."
        Exit Sub
    End If

    filePath = ThisWorkbook.Path & Application.PathSeparator & "RevenueChart.pdf"
    chartObject.Chart.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filePath
    MsgBox "PDF exported to: " & filePath
End Sub

Exporting a single chart as PDF is different from exporting a worksheet or the entire workbook. If you need several charts in one PDF, exporting each chart separately creates separate files; arranging them on a worksheet and exporting that sheet is often more suitable. Review page layout and print settings when using the worksheet approach.

Find the correct chart reliably

The name in ChartObjects("Chart 1") is the chart object’s name, not necessarily the visible title displayed above the plot. Select the chart and inspect its name in Excel’s Name Box, or use the Selection Pane to identify and rename objects. Clear names such as SalesByRegion are easier to maintain than default names when a workbook has many charts.

Use the worksheet’s actual tab name in Worksheets("Report"). A renamed tab, a misspelled chart name, or a chart that has been deleted will cause a runtime error. If your chart is on a separate chart sheet, use a chart-sheet reference instead, for example Charts("Chart 1").Export with the appropriate arguments. Do not use a worksheet’s ChartObjects collection for a chart sheet.

When a workbook contains several worksheets with identical chart object names, qualify each chart with its worksheet as in the examples. This prevents VBA from depending on whichever sheet happens to be active. For a reusable macro, you can also make the worksheet name, chart name, and destination filename configurable rather than embedding them in the code.

Control the exported appearance

The exported file reflects the chart’s existing formatting and dimensions, including its title, legend, labels, colors, and plot area. Set those details in Excel before exporting. There is no DPI argument in the basic Chart.Export call, so do not expect a setting such as Resolution:=300 to work there. If an image looks too small in a report, enlarging the chart before export may help, but check the labels and proportions after resizing.

Export a chart only after its data and formatting are in their intended state. If formulas are still recalculating or the chart depends on refreshed external data, make sure the workbook has updated before the macro runs. A chart can export successfully and still show stale values if its source has not refreshed.

  • Use a descriptive file name and include the date or reporting period when repeated exports must be distinguishable.
  • Choose a destination folder the user can write to; a workbook stored in a cloud location may expose a URL rather than a normal local path.
  • Open the output file to verify cropping, text size, and whether the intended chart was exported.

Export several charts

For a routine report, a macro can loop through a worksheet’s ChartObjects collection and export each chart. The loop should construct a different file name for every chart, usually using the object’s name or a controlled label. Check for characters that are invalid in Windows file names, such as a colon or a slash, before using chart names as file names. Also decide what should happen if an output file already exists: Excel may replace it, so use a dated name or ask before overwriting when preserving prior exports matters.

Not every chart on a sheet necessarily belongs in the export. A loop over all chart objects will include charts hidden behind other objects or charts used only for internal analysis unless the macro filters them. If the report requires a selected subset, keep an explicit list of chart names and export only those. This makes the output predictable when someone later adds another chart to the worksheet.

Common export problems

  • Object not found: Confirm the worksheet tab name and chart object name. The chart title is not a substitute for the object’s name.
  • Invalid or unavailable path: Make sure the workbook has been saved and that the target folder exists and is writable. A path on a network or cloud service may require a local synced folder.
  • Unexpected format: Match the filename extension to the filter, such as .png with PNG. A mismatched extension can confuse applications even if a file is produced.
  • Blank or outdated chart: Check that the chart has visible data and that linked formulas or external data have refreshed before export.
  • Macro will not run: Excel for the web cannot run VBA macros. Open the workbook in desktop Excel and use a macro-enabled workbook, commonly saved as .xlsm, if you need to retain VBA code.

For troubleshooting, first try exporting one chart to a short, known local path and inspect whether the macro reports success. Then add the desired folder, naming scheme, and batch logic. This isolates a chart reference or format issue from a permissions or path issue.

Excel on Mac and macro safety

VBA is available in desktop Excel for Mac, but Excel for the web does not execute VBA. Menu labels, keyboard shortcuts, file paths, and available graphic filters can differ between Mac and Windows. The examples use Application.PathSeparator to avoid hard-coding a slash, but a cloud URL or a folder that is not locally accessible can still prevent a file from being written. Test the export on the target computer and verify the resulting file.

Only run macros from workbooks you trust. On Windows, Excel’s macro controls are under File > Options > Trust Center > Trust Center Settings > Macro Settings. Avoid enabling all macros globally just to run one export; follow your organization’s policy and enable or unblock only trusted files as appropriate. Keep an untouched copy of important workbooks before running VBA.

Frequently Asked Questions

Can Excel VBA export a chart as a PNG?
Yes. Call the chart’s Export method with a PNG file name and FilterName:="PNG". The chart must be referenced correctly, and the destination must be writable.

Can VBA export an Excel chart as a PDF?
Yes. Use Chart.ExportAsFixedFormat with Type:=xlTypePDF and a PDF filename. This exports the chart; exporting a whole worksheet or workbook is a different operation.

How do I export a chart without selecting it first?
Refer to the worksheet and chart by name, as in Worksheets("Report").ChartObjects("Chart 1").Chart. This is more dependable than using ActiveChart, which relies on the current selection.

Can Excel for the web run a chart-export macro?
No. Excel for the web can open and edit many workbooks but does not run VBA. Use desktop Excel for Windows or Mac to run the macro.

Does exporting a chart include its source data?
No. PNG and PDF exports are visual outputs. The chart’s source cells and formulas remain in the workbook and are not embedded as editable spreadsheet data in the exported image.

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.