I'm trying to export all charts within my Excel file as a PNG image. The charts are not embedded in the worksheets, but have instead been moved as a new sheet upon creation.
Not being familiar with VBA or office macros, I've tried stringing together something based on code examples I found on the web but with no success.
Here's what I've tried, which may work with charts embedded within worksheets but not with standalone charts:
Private Sub ExportChartsButton_Click()
Dim outFldr As String
Dim ws As Worksheet
Dim co As ChartObject
outFldr = GetFolder(ActiveWorkbook.Path)
For Each ws In ActiveWorkbook.Worksheets
For Each co In ws.ChartObjects
co.Export outFldr & "\" & ws.Name & ".png", "PNG"
Next
Next
End Sub
When the button is clicked, nothing seems to happen.
If I replace the inner loop with MsgBox co.ChartObjects.Count
I get a 0
popup for each of my non-chart worksheets, so I'm obvious not iterating through the right objects (hence, no charts so nothing happens).
So, how do I iterate through Charts that are not embedded within worksheets?