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

27

4

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.

fmark

Posted 2011-05-12T10:12:08.233

Reputation: 1 587

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

– Jon Peltier – 2011-12-01T16:22:11.957

Answers

34

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.

DMA57361

Posted 2011-05-12T10:12:08.233

Reputation: 17 581

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 – 2011-05-12T10:40:32.083

@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 – 2011-05-12T10:47:38.687

@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 – 2011-05-12T11:24:19.360

Cheers! I'll give it a whirl. – fmark – 2011-05-12T12:15:57.737

4

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.

João Pimentel

Posted 2011-05-12T10:12:08.233

Reputation: 41

I have to fully agree this is really the fastest method. By far. – Jeef – 2017-05-30T18:35:37.823

3

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.

sgildea

Posted 2011-05-12T10:12:08.233

Reputation: 31

2

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.

Dave Mulligan

Posted 2011-05-12T10:12:08.233

Reputation: 181

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 – 2014-02-20T14:36:55.127

Excel 2011 for Mac is what I'm using. – Dave Mulligan – 2014-02-20T21:23:59.797

0

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.

Will Martin

Posted 2011-05-12T10:12:08.233

Reputation: 821

0

If you're using Greenshot (a screen capture software), then you can copy the graph in Excel (Ctrl+C), then right-click Greenshot's icon, select Open image from clipboard and save it. No need to use graphics editor.

gronostaj

Posted 2011-05-12T10:12:08.233

Reputation: 33 047