Microsoft Office Tutorials and References
In Depth Information
Exporting a Chart
The procedure that follows uses the Export method of the Chart object to save the active
chart as a GIF file:
Sub SaveChartAsGIF ()
Dim Fname as String
If ActiveChart Is Nothing Then Exit Sub
Fname = ThisWorkbook.Path & “\” & ActiveChart.Name & “.gif”
ActiveChart.Export FileName:=Fname, FilterName:=”GIF”
End Sub
Other choices for the FilterName argument are “JPEG” and “PNG” . Usually, GIF and PNG files
look better. The Help system lists a third argument for the Export method: Interactive . If
this argument is True , you’re supposed to see a dialog box in which you can specify export
options. However, this argument has no effect.
Keep in mind that the Export method will fail if the user doesn’t have the specified graphics
export filter installed. These filters are installed in the Office (or Excel) setup program.
Exporting all graphics
One way to export all graphic images from a workbook is to save the file in HTML format. Doing
so creates a directory that contains GIF and PNG images of the charts, shapes, clipart, and even
copied range images (created with Home Clipboard Paste Picture (U)).
Here’s a VBA procedure that automates the process. It works with the active workbook:
Sub SaveAllGraphics()
Dim FileName As String
Dim TempName As String
Dim DirName As String
Dim gFile As String
FileName = ActiveWorkbook.FullName
TempName = ActiveWorkbook.Path & “\” & _
ActiveWorkbook.Name & “graphics.htm”
DirName = Left(TempName, Len(TempName) - 4) & “_files”
‘ Save active workbookbook as HTML, then reopen original
ActiveWorkbook.SaveAs FileName:=TempName, FileFormat:=xlHtml
Application.DisplayAlerts = False
Workbooks.Open FileName
‘ Delete the HTML file
Kill TempName
‘ Delete all but *.PNG files in the HTML folder
Search JabSto ::

Custom Search