I am trying to loop through all charts in a workbook. Why is option 1 working, but option 2 not?
'OPTION 1
For Each sht In ActiveWorkbook.Worksheets
For Each cht In sht.ChartObjects
MsgBox (cht.Name)
Next cht
Next sht
'OPTION2
Dim oChart As Chart
For Each oChart In Application.Charts
MsgBox (oChart.Name)
Next oChart
End Sub
There are two flavors of charts:
This code:
will display information about the "big" variety.
and if you want information on the "little" charts:
As the documentation states,
Application.Charts
returns aSheets
collection containg all chart sheets (not charts!). ForWorksheet.ChartObjects
, however, the documentation says that it returns aChartObjects
collection containing all charts on that sheet.