Class ChartObject (Excel VBA)

The class ChartObject represents an embedded chart on a worksheet.

The main procedures of class ChartObject are Activate, Copy, Delete, Select, ChartObjects.Add, ChartObjects.Copy, ChartObjects.Delete and ChartObjects.Select

Set

To use a ChartObject class variable it first needs to be instantiated, for example

Dim chro as ChartObject
Set chro = ActiveSheet.ChartObjects(Index:=1)

The following procedures can be used to set variables of type ChartObject: Duplicate, ChartObjects.Item, ChartObjects.Add, Chart.ChartObjects, ChartObjects.Duplicate and Worksheet.ChartObjects

For Each

Here is an example of processing the ChartObject items in a collection.

Dim chro As ChartObject
For Each chro In ActiveSheet.ChartObjects()
	
Next chro

Themes

Some procedures in this class have been grouped together in themes and are described on separate theme pages

Cell with its procedures BottomRightCell and TopLeftCell
Copy with its procedures Copy, CopyPicture, ChartObjects.Copy and ChartObjects.CopyPicture
Print with its procedures PrintObject and ChartObjects.PrintObject

Methods

These are the main methods of the ChartObject class

Activate - Makes the current chart the active chart.

ActiveSheet.ChartObjects(1).Activate

Delete - Deletes the object.

ActiveSheet.ChartObjects(1).Delete

Select - Selects the object.

ActiveSheet.ChartObjects(1).Select

ChartObjects.Add - Creates a new embedded chart.

Set co = Sheets("Sheet1").ChartObjects.Add(50, 40, 200, 100) 
co.Chart.ChartWizard Source:=Worksheets("Sheet1").Range("A1:B2"), _ 
 Gallery:=xlColumn, Format:=6, PlotBy:=xlColumns, _ 
 CategoryLabels:=1, SeriesLabels:=0, HasLegend:=1

ChartObjects.Delete - Deletes the object.

ActiveSheet.ChartObjects.Delete

ChartObjects.Select - Selects the object.

ActiveSheet.ChartObjects.Select

Other Methods

BringToFront - Brings the object to the front of the z-order.

Cut - Cuts the object to the Clipboard.

Duplicate - Duplicates the object and returns a reference to the new copy.

SendToBack - Sends the object to the back of the z-order.

ChartObjects.Cut - Cuts the object to the Clipboard.

ChartObjects.Duplicate - Duplicates the chartobject and returns a reference to the new copy.

ChartObjects.Item - Returns a single object from a collection.

Properties

Chart returns a Chart object that represents the chart contained in the object.

Height returns or sets a Double value that represents the height, in points, of the object.

Index returns a Long value that represents the index number of the object within the collection of similar objects.

Left returns or sets a Double value that represents the distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart).

Locked returns or sets a Boolean value that indicates if the object is locked.

Name returns a String value representing the name of the object.

Parent returns the parent object for the specified object. Read-only.

Placement returns or sets a Variant value, containing an XlPlacement constant, that represents the way the xlplacement is attached to the cells below it.

ProtectChartObject true if the embedded chart frame cannot be moved, resized, or deleted through the user interface.

RoundedCorners true if the embedded chart has rounded corners.

Shadow returns or sets a Boolean value that determines if the font is a shadow font or if the object has a shadow.

ShapeRange returns a ShapeRange object that represents the specified object or objects.

Top returns or sets a Double value that represents the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).

Visible returns or sets a Boolean value that determines whether the object is visible.

Width returns or sets a Double value that represents the width, in points, of the object.

ZOrder returns the z-order position of the object.

ChartObjects.Count returns a Long value that represents the number of objects in the collection.

ChartObjects.Height returns or sets a Double value that represents the height, in points, of the object.

ChartObjects.Left returns or sets a Double value that represents the distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart).

ChartObjects.Locked returns or sets a Boolean value that indicates if the objects are locked.

ChartObjects.Parent returns the parent object for the specified object. Read-only.

ChartObjects.Placement returns or sets a Variant value, containing an XlPlacement constant, that represents the way the xlplacements are attached to the cells below them.

ChartObjects.ProtectChartObject true if the embedded chart frame cannot be moved, resized, or deleted through the user interface.

ChartObjects.ShapeRange returns a ShapeRange object that represents the specified object or objects.

ChartObjects.Top returns or sets a Double value that represents the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).

ChartObjects.Visible returns or sets a Boolean value that determines whether the object is visible.

ChartObjects.Width returns or sets a Double value that represents the width, in points, of the object.