Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Export Chart to file (2002/SP3)

    I have an embedded chart object in my worksheet. I'm wrote a code which will export the chart to a GIF file, but it comes with an Run-time error '91' in line 7. How can I fix this?

    Private Sub SaveGIF_Click()
    Dim chtChart As ChartObject
    Dim FileName
    FileName = "Temperature.gif"
    FileName = Application.GetSaveAsFilename(FileName)
    If FileName <> False Then
    chtChart.Chart("TemperatureChart").ExportPicture FileName, Width:=320, Height:=240
    End If
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Export Chart to file (2002/SP3)

    Your code makes little sense.

    1) You declare a variable chtChart but don't assign it a value, so it is empty when you try to export it.
    2) chtChart.Chart("TemperatureChart") is meaningless.
    3) ExportPicture is not a method of any object in Excel.

    Try this:

    Set chtChart = ActiveSheet.ChartObjects("TemperatureChart")
    chtChart.Chart.Export FileName, "GIF"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •