Sunday, March 15, 2009

How to Save a Chart as Image using Excel VBA

Here is the way to save the active chart in Excel 2007 to a JPG file. It is better to size the chart appropriately before exporting it as an image.

Sub Save_ChartAsImage()

Dim oCht As Chart

Set oCht = ActiveChart

On erRROR GoTo Err_Chart

oCht.Export Filename:="C:\PopularICON.jpg", Filtername:="JPG"

Err_Chart:

If Err <> 0 Then

Debug.Print Err.Description

Err.Clear

End If

End Sub

The code uses Export method to save the chart in graphics format

7 comments:

  1. this is a best way to convert a excel sheet into a image file

    ReplyDelete
  2. Anonymous10:36 AM

    It works for me. I Love it !!!

    ReplyDelete
  3. Anonymous7:33 AM

    Is there a way to do the same with a table/group of formatted cells? i.e. export as .JPEG using vba.

    ReplyDelete
  4. Can you check if the following works for you http://vbadud.blogspot.com/2010/06/how-to-save-excel-range-as-image-using.html

    ReplyDelete
  5. Changing the jpg line to a png allows for a crisper export.

    oCht.Export Filename:="C:\ExcelChartExport.png", Filtername:="png"

    Jpgs work well for pictures of people and things just not computer output..

    I also changed the name of the export..
    Thanks for the tip !!

    ReplyDelete
  6. Anonymous8:24 AM

    Can this be done with a shape object, such as a picture? I'm tearing my hair out on this. Excel 2003.

    ReplyDelete
  7. Anonymous12:58 AM

    but image is not clear......

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.