Page 236 - Excel Progamming Weekend Crash Course
P. 236
n540629 ch17.qxd 9/2/03 9:35 AM Page 211
Session 17 — Introduction to Charts 211
In either case, the charts are the same in terms of the properties and methods you use
to work with them; however, there are a few differences in the way to refer to and create
embedded charts and chart sheets.
Embedded Charts
An embedded chart is the better choice when you want the chart displayed as part of a
worksheet along with the data and/or other charts. Each embedded chart is represented by
a Chart object. This Chart object is contained within a ChartObject object. This seemingly
confusing arrangement is necessary because the Chart object itself does not have any provi-
sion for specifying the size or the position of the chart — these tasks are taken care of by
the ChartObject object.
Each Excel worksheet has a ChartObjects collection that contains one entry for each
embedded chart on the worksheet. To add a new embedded chart to a worksheet, you add
a ChartObject to this collection. The syntax is:
SomeWorksheet.ChartObjects.Add(Left, Top, Width, Height)
Left and Top specify the position of the chart’s top left corner, and Width and Height
specify its size. All four arguments are measured in points, a unit equal to ⁄72 inch. The
1
method returns a reference to the newly created ChartObject. You then use the Chart
property to reference the contained chart. For example:
Dim co As ChartObject
Dim ch As Chart
Set co = Worksheets(“Sheet1”).ChartObjects.Add(50, 50, 250, 165)
Set ch = co.Chart
After this code executes, a new blank embedded chart exists on Sheet1. You would use
the variable ch to refer to it.
More information on the ChartObject object is presented later in this session.
If a chart overlaps worksheet data, the data is still there but is not visible.
You can show the data by moving the chart or by hiding it.
Note
Chart Sheets
Use a Chart Sheet when you want a chart displayed at the maximum size without distraction
from data or other charts. A chart sheet is represented by a Chart object, just like an embed-
ded chart is. Unlike an embedded chart, no ChartObject is required because the position of
a chart on a chart sheet is fixed, and its size is dependent on the size of the sheet. Each
workbook has a Charts collection that contains all of the chart sheets in that workbook.