Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I save a graph to a PNG or GIF file in Microsoft Excel?

I know I can save as an HTML file and use the image created there, but I suspect there is a way that doesn't create other clutter of files I don't want. I'm happy to install an add-in if that is the recommended option.

I'm using Excel 2003 and 2007 if that matters.

share|improve this question
add comment

7 Answers

up vote 18 down vote accepted

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.

share|improve this answer
    
I would prefer to have a way to export it into the same folder as the current spreadsheet at the press of a button –  fmark May 12 '11 at 10:40
    
@fmark - then that's where the macro comes in, something like ActiveChart.Export ActiveWorkbook.Path & "\chart.png" (but maybe a little bit smarter!) in a macro bound to a toolbar button would do the job. –  DMA57361 May 12 '11 at 10:47
    
@fmark, I got bored and had a few minutes so I've thrown together something much more complete. Check out the edit, I think that'll give you a really solid starting point. –  DMA57361 May 12 '11 at 11:24
    
Cheers! I'll give it a whirl. –  fmark May 12 '11 at 12:15
add comment

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 AsOther 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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Old thread, but just in case anyone else lands here from Google: Excel now has a "Save as Picture" option on the right-click menu for doing exactly this.

share|improve this answer
    
What version of Excel? My Excel 2007 definitely does not have this. Sticking with a 7 year old Office is probably a "cost saving measure". –  Ogre Psalm33 Feb 20 at 14:36
    
Excel 2011 for Mac is what I'm using. –  Dave Mulligan Feb 20 at 21:23
add comment

Here's an explanation and a link to an Excel Add-In (free) that will do it for you:

Enhanced Export Chart Procedure

share|improve this answer
add comment

I'm using a screen capture tool (Greenshot) to save my Excel graphs as image files.

share|improve this answer
add comment

In Excel 2010, you can do this by:

  1. Click the chart to select it.
  2. Copy using CTRL+C, or by right-clicking and selecting Copy.
  3. Switch to a graphics editing program (I used Paint.net).
  4. Paste.

Then you can save the image in whatever format you please.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.