Chart Object [Excel 2003 VBA Language Reference]

Multiple objects
Multiple objects

Represents a chart in a workbook. The chart can be either an embedded chart (contained in a ChartObject ) or a separate chart sheet.

Using the Chart Object

The following properties and methods for returning a Chart object are described in this section:

  • Chart property
  • Charts method
  • ActiveChart property
  • ActiveSheet property

Chart Property

Use the Chart property to return a Chart object that represents the chart contained in a ChartObject object. The following example sets the pattern for the chart area in embedded chart one on the worksheet named "Sheet1."

Worksheets("Sheet1").ChartObjects(1).Chart. _
    ChartArea.Interior.Pattern = xlLightDown

Charts Method

The Charts collection contains a Chart object for each chart sheet in a workbook. Use Charts(index), where index is the chart-sheet index number or name, to return a single Chart object. The following example changes the color of series one on chart sheet one.

Charts(1).SeriesCollection(1).Interior.Color = RGB(255, 0, 0)

The chart index number represents the position of the chart sheet on the workbook tab bar. Charts(1) is the first (leftmost) chart in the workbook; Charts(Charts.Count) is the last (rightmost). All chart sheets are included in the index count, even if they're hidden. The chart-sheet name is shown on the workbook tab for the chart. You can use the Name property to set or return the chart name.

The following example moves the chart named Sales to the end of the active workbook.

Charts("Sales").Move after:=Sheets(Sheets.Count)

The Chart object is also a member of the Sheets collection. The Sheets collection contains all the sheets in the workbook (both chart sheets and worksheets). Use Sheets(index), where index is the sheet index number or name, to return a single sheet.

ActiveChart Property

When a chart is the active object, you can use the ActiveChart property to refer to it. A chart sheet is active if the user has selected it or it's been activated with the Activate method. The following example activates chart sheet one and then sets the chart type and title.

With ActiveChart
    .Type = xlLine
    .HasTitle = True
    .ChartTitle.Text = "January Sales"
End With

An embedded chart is active if the user has selected it or the ChartObject object that it's contained in has been activated with the Activate method. The following example activates embedded chart one on worksheet one and then sets the chart type and title. Notice that after the embedded chart has been activated, the code in this example is the same as that in the previous example. Using the ActiveChart property allows you to write Visual Basic code that can refer to either an embedded chart or a chart sheet (whichever is active).

ActiveChart.Type = xlLine
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "January Sales"

ActiveSheet Property

When a chart sheet is the active sheet, you can use the ActiveSheet property to refer to it. The following example uses the Activate method to activate the chart sheet named Chart1 and then sets the interior color for series one in the chart to blue.

ActiveSheet.SeriesCollection(1).Interior.ColorIndex = 5

Properties | Application Property | Area3DGroup Property | AutoScaling Property | Bar3DGroup Property | BarShape Property | ChartArea Property | ChartTitle Property | ChartType Property | CodeName Property | Column3DGroup Property | Corners Property | Creator Property | DataTable Property | DepthPercent Property | DisplayBlanksAs Property | Elevation Property | Floor Property | GapDepth Property | HasAxis Property | HasDataTable Property | HasLegend Property | HasPivotFields Property | HasTitle Property | HeightPercent Property | Hyperlinks Property | Index Property | Legend Property | Line3DGroup Property | MailEnvelope Property | Name Property | Next Property | PageSetup Property | Parent Property | Perspective Property | Pie3DGroup Property | PivotLayout Property | PlotArea Property | PlotBy Property | PlotVisibleOnly Property | Previous Property | ProtectContents Property | ProtectData Property | ProtectDrawingObjects Property | ProtectFormatting Property | ProtectGoalSeek Property | ProtectionMode Property | ProtectSelection Property | RightAngleAxes Property | Rotation Property | Scripts Property | Shapes Property | ShowWindow Property | SizeWithWindow Property | SurfaceGroup Property | Tab Property | Visible Property | Walls Property | WallsAndGridlines2D Property

Methods | Activate Method | ApplyCustomType Method | ApplyDataLabels Method | AreaGroups Method | Axes Method | BarGroups Method | ChartGroups Method | ChartObjects Method | ChartWizard Method | CheckSpelling Method | ColumnGroups Method | Copy Method | CopyPicture Method | CreatePublisher Method | Delete Method | Deselect Method | DoughnutGroups Method | Evaluate Method | Export Method | GetChartElement Method | LineGroups Method | Location Method | Move Method | OLEObjects Method | Paste Method | PieGroups Method | PrintOut Method | PrintPreview Method | Protect Method | RadarGroups Method | Refresh Method | SaveAs Method | Select Method | SeriesCollection Method | SetBackgroundPicture Method | SetSourceData Method | Unprotect Method | XYGroups Method

Events | Activate Event | BeforeDoubleClick Event | BeforeRightClick Event | Calculate Event | Deactivate Event | DragOver Event | DragPlot Event | MouseDown Event | MouseMove Event | MouseUp Event | Resize Event | Select Event | SeriesChange Event

Parent Objects | Application Object | ChartObject Object | Window Object | Workbook Object

Child Objects | ChartArea Object | ChartGroup Object | ChartTitle Object | Corners Object | DataTable Object | Floor Object | Hyperlinks Object | Legend Object | PageSetup Object | PivotLayout Object | PlotArea Object | Shapes Object | Tab Object | Walls Object

See Also | Controlling One Microsoft Office Application from Another | OLE Programmatic Identifiers