Microsoft Office Tutorials and References
In Depth Information
Looping through All Charts
Figure 18-3: Attempting to delete one or more chart sheets results in this message.
Looping through All Charts
In some cases, you may need to perform an operation on all charts. The following example
applies changes to every embedded chart on the active worksheet. The procedure uses a loop to
cycle through each object in the ChartObjects collection and then accesses the Chart object
in each and changes several properties.
Sub FormatAllCharts()
Dim ChtObj As ChartObject
For Each ChtObj In ActiveSheet.ChartObjects
With ChtObj.Chart
.ChartType = xlLineMarkers
.ApplyLayout 3
.ChartStyle = 12
.ClearToMatchStyle
.SetElement msoElementChartTitleAboveChart
.SetElement msoElementLegendNone
.SetElement msoElementPrimaryValueAxisTitleNone
.SetElement msoElementPrimaryCategoryAxisTitleNone
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 1000
End With
Next ChtObj
End Sub
This example is available on the companion CD-ROM. The filename is format all
charts.xlsm .
Figure 18-4 shows four charts that use a variety of different formatting; Figure 18-5 shows the
same charts after running the FormatAllCharts macro.
 
Search JabSto ::




Custom Search