Chapter 21. The Chart Object

Excel charts are represented by Chart objects in the Excel object model. Since charts are quite complex, the Chart object is one of the most complicated in the object model.

To set the terminology, Figure 21-1 shows a typical chart that has been labeled with some of the commonly used chart-related terms.

Some chart terminology

Figure 21-1. Some chart terminology

Figure 21-2 shows the Chart object and its immediate children.

The Chart object

Figure 21-2. The Chart object

As you probably know, Excel charts can reside in a special type of sheet called a chart sheet or they can be embedded in an ordinary worksheet. Accordingly, a Chart object can represent a chart sheet (standalone chart) or an embedded chart. In the latter case, the Chart object is not contained directly in a worksheet. Rather, the worksheet contains a ChartObject object that acts as a container for the Chart object.

Thus, for instance, if we create a new chart using the chart wizard, the fourth step in the wizard displays the dialog shown in Figure 21-3.

If we choose the "As new sheet" option in step 4 of the chart wizard, we can access the resulting chart using the code:

Dim c as Chart
Set c = ThisWorkbook.Charts("Chart1")

On the other hand, choosing the "As object in" option in step 4 of the chart wizard, we access the chart using the code:

Dim c As Chart
Set c = Worksheets("Sheet1").ChartObjects("Chart 1").Chart

Note the space between the word Chart and the number 1 in the name of the ChartObject object, but not in the name of the Chart object.

We emphasize that there is no ChartSheet object. The Charts property of the Application object returns a so-called Sheets collection containing one Chart object for each chart sheet. It does not contain Chart objects for the embedded charts.