VB and VBA Users Source Code: Exporting an Excel Chart to a gif image file
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Exporting an Excel Chart to a gif image file
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, June 24, 2003
Hits:
1752
Category:
Office
Article:
The code below can be used to export and Excel Chart object to an image file. Note, an example is included in the code header. Option Explicit 'Purpose : Exports an Excel Chart to a GIF file 'Inputs : oChart The chart to export ' sFilePath The path to save the image file to. ' [bOverwrite] If True will overwrite any existing images. 'Outputs : Returns True on success. 'Author : Andrew Baker 'Date : 03/09/2002 'Example : ' If ChartToGif(Sheet1.ChartObjects(1).Chart, "C:\Chart.gif", True) Then ' Shell "mspaint.exe ""C:\Chart.gif""" ' End If 'Notes : 'Revisions : Function ChartToGif(oChart As Chart, sFilePath As String, Optional bOverwrite As Boolean = True) As Boolean If bOverwrite Then On Error Resume Next 'Delete any existing file VBA.Kill sFilePath End If 'Export the chart On Error GoTo ErrFailed oChart.Export sFilePath ChartToGif = True Exit Function ErrFailed: 'Failed Debug.Print "Error in ChartToGif: " & Err.Description ChartToGif = False End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder