0

I'm struggling to find the correct syntax to export a chart from a chart sheet, not embedded in a worksheet. I used to have the chart embedded, but transferred it to it's own sheet at the request of the user and I can't seem to find anything to suit. Here is the code as it stood with an embedded chart, could someone give me a hint as to the syntax?

Public Sub ExportChart()

    Dim varChartObject As ChartObject
    Dim varChart As Chart
    Dim varFilename As String
    Dim varPath As String

    Set varChartObject = Sheets("Output Chart").ChartObjects(1)
    Set varChart = varChartObject.Chart
    varFilename = Format(ThisWorkbook.Sheets("Parameters").Range("C5").Value, "YYYYMMDD")
    varPath = "MyPath\" & Format(ThisWorkbook.Sheets("Parameters").Range("C5").Value, "MM. MMMM")

    On Error Resume Next
    Kill varPath & "\" & varFilename
    On Error GoTo 0

    varChart.Export Filename:=varPath & "\" & varFilename & ".png", Filtername:="PNG"

    Set varChartObject = Nothing
    Set varChart = Nothing

End Sub

Thanks in advance

1 Answer 1

2

You only need this at the start:

Set varChart = Charts("chart sheet name")
Sign up to request clarification or add additional context in comments.

1 Comment

Unbelieveable. I've been looking for this for days and trying out all different syntaxs. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.