How can I save a graph to a PNG or GIF file in Microsoft Excel?
Excel lacks any user-accessible support for this functionality, but you can either easily work around this or dig in to VBA, where this functionality is provided:
"One-shot" export
- Select the graph (the whole graph, not an internal component; so select the border).
- Copy it (ctrl-c, right-click copy, whatever you like).
- Open MS Paint.
- Paste (you may wish to minimise the image size first, it will get enlarged to fit, but not shrunk).
- Save as desired.
Bulk export
You would probably want to look at using ActiveChart.Export
in a VBA macro, this lets you specify a file path and then lets Excel do the work.
Below is a working prototype that I've just put together. Run this and every chart in the active workbook will be exported to the same folder as that file, in PNG format, with _chart##
appended to the file name (where ##
is an increasing number).
It doesn't perform any safety checks (so will overwrite files!) and doesn't contain any error checking. It will not work if you haven't yet saved the workbook, the location is read-only or anything else that prevents writing to the file's location. I have only tested this in Excel 2003 (as that's all I have to hand at the moment).
In other words: Use at your own risk, this is intended as a basic working example only.
'small nicety to ensure two-digits for better file sorting'
Function NiceFileNumber(num As Integer) As String
If num < 10 Then
NiceFileNumber = "0" & num
Else
NiceFileNumber = num
End If
End Function
'the real function'
Sub ExportAllCharts()
Dim i As Integer, exportCount As Integer
Dim fileNum As String, fileBase As String
Dim sheetObj As Worksheet
Dim chartObj As Chart
'current file location and name, with extension stripped'
fileBase = Left(ThisWorkbook.FullName, InStrRev(ThisWorkbook.FullName, ".") - 1)
exportCount = 0
'First, export all charts that are in their own sheets'
For Each chartObj In ActiveWorkbook.Charts
fileNum = NiceFileNumber(exportCount)
exportCount = exportCount + 1
'Do the export'
chartObj.Export fileBase & "_chart" & fileNum & ".png"
Next
'Then, export all charts that are embedded inside normal sheets'
For Each sheetObj In ActiveWorkbook.Worksheets
For i = 1 To sheetObj.ChartObjects.count
fileNum = NiceFileNumber(exportCount)
exportCount = exportCount + 1
'Do the export'
sheetObj.ChartObjects(i).Activate
ActiveChart.Export fileBase & "_chart" & fileNum & ".png"
Next i
Next
End Sub
Note: I've encased the comments in '
s at both ends, which isn't needed, but helps make sure they're coloured correctly here.
The best way is to save the Excel file as HTML.
Then go to the folder where images were stored and you'll see the PNG images you want.
To safely convert to PNG you can copy the figure from Excel, paste it onto a slide in Power Point, and then do the following.
Save As → Other Formats, then select your desired format. It will then ask if you'd like to apply this to the current slide only, or all the slides. If you select all slides, it creates a folder in the directory you specify, and saves each slide to its own file in the selected format.
It's not very elegant, but it can be quick enough when you just need the files, and is especially helpful if you've already made a presentation with the same graphs.
Old thread, but just in case anyone else lands here from Google: Excel 2011 for Mac has a "Save as Picture" option on the right-click menu for doing exactly this.