Microsoft Office Tutorials and References
In Depth Information
Creating an Embedded Chart
For a chart sheet, the object hierarchy is a bit different because it doesn’t involve the
Worksheet object or the ChartObject object. For example, here’s the hierarchy for the
ChartTitle object for a chart in a chart sheet:
Application
Workbook
Chart
ChartTitle
In terms of VBA, you could use this statement to set the chart title in a chart sheet to YTD Sales :
Sheets(“Chart1”).ChartTitle.Text = “YTD Sales”
A chart sheet is essentially a Chart object, and it has no containing ChartObject object. Put
another way, the parent object for an embedded chart is a ChartObject object, and the parent
object for a chart on a separate chart sheet is a Workbook object.
Both of the following statements will display a message box with the word Chart in it:
MsgBox TypeName(Sheets(“Sheet1”).ChartObjects(1).Chart)
Msgbox TypeName(Sheets(“Chart1”))
When you create a new embedded chart, you’re adding to the ChartObjects
collection and the Shapes collection contained in a particular worksheet. (There is no
Charts collection for a worksheet.) When you create a new chart sheet, you’re adding
to the Charts collection and the Sheets collection for a particular workbook.
Creating an Embedded Chart
A ChartObject is a special type of Shape object. Therefore, it’s a member of the Shapes
collection. To create a new chart, use the AddChart method of the Shapes collection. The
following statement creates an empty embedded chart:
ActiveSheet.Shapes.AddChart
The AddChart method can use five arguments (all are optional):
h Type: The type of chart. If omitted, the default chart type is used. Constants for all the
chart types are provided (for example, xlArea , xlColumnClustered , and so on).
h Left: The left position of the chart, in points. If omitted, Excel centers the chart horizontally.
 
Search JabSto ::




Custom Search