Microsoft Office Tutorials and References
In Depth Information
Counting and Looping through Charts
charts. The result is a listing of all embedded charts on all worksheets. The result of
running this macro is shown in Figure 16-3. This workbook contains seven
embedded charts on three sheets.
Figure 16-3: Displaying the names of all embedded charts
on all worksheets.
Sub LoopThruChartObjects2()
Dim Wks As Worksheet
Dim ChtObj As ChartObject
Dim Msg As String
Msg = “”
For Each Wks In ActiveWorkbook.Worksheets
For Each ChtObj In Wks.ChartObjects
Msg = Msg & Wks.Name & “ - “ & ChtObj.Name & vbNewLine
Next ChtObj
Msg = Msg & vbNewLine
Next Wks
MsgBox Msg
End Sub
The previous examples looped through embedded charts. The following
procedure is similar, but it loops through all Chart sheets in the active workbook.
Sub LoopThruChartSheets()
Dim Cht As Chart
Dim Msg As String
Msg = “”
For Each Cht In ActiveWorkbook.Charts
Msg = Msg & Cht.Name & vbNewLine
Next Cht
MsgBox Msg
End Sub
Search JabSto ::




Custom Search