PDA

View Full Version : Save Chart As A Picture VBA



Admin
05-14-2011, 04:28 PM
Hi All,

Here is a routine which converts the chart into a picture (GIF, BMP, JPG)

Put this macro in a Standard module.


Public Enum PicType
GIF = 1
JPG = 2
BMP = 3
End Enum
Sub SaveChartAs(ByRef Chart_Object As ChartObject, ByVal PictureType As PicType, _
Optional ByVal FilePath As String, Optional ByVal FileName As String)

Dim Extn As String

Extn = Application.Choose(PictureType, ".GIF", ".JPG", ".BMP")

If Len(FilePath) = 0 Then FilePath = ThisWorkbook.Path
If Len(FileName) = 0 Then
FileName = Chart_Object.Chart.Name & Extn
Else
FileName = FileName & Extn
End If


Chart_Object.Chart.Export FilePath & "\" & FileName, Mid$(Extn, 2)

End Sub

and call the routine like ..


Sub kTest()

SaveChartAs ActiveSheet.ChartObjects(1), JPG, "C:\Test", "MyImage"

End Sub

Enjoy !