Modifying the chart type

Here's a confusing statement for you: A ChartObject object acts as a container for a Chart object.

To modify a chart with VBA, you don't have to activate the chart. Rather, the Chart method can return the chart contained in the ChartObject. Are you thoroughly confused yet? The following two procedures have the same effect — they change the chart named Chart 1 to an area chart. The first procedure activates the chart first; the second one doesn't. The built-in constant xlArea represents an area chart.

Sub ModifyChart1()

ActiveSheet.ChartObjects("Chart 1").Activate ActiveChart.Type = xlArea ActiveWindow.Visible = False End Sub

Sub ModifyChart2()

ActiveSheet.ChartObjects("Chart 1").Chart.Type = xlArea End Sub

0 0

Post a comment