Remarks

Each ChartObject object represents an embedded chart. The ChartObject object acts as a container for a object. Properties and methods for the ChartObject object control the appearance and size of the embedded chart on the sheet. ChartObjects collection

Example

Use the method to return the ChartObjects collection. The following example deletes all the embedded charts on the worksheet named "Sheet1."

Visual Basic for Applications
Worksheets("sheet1").ChartObjects.Delete

You cannot use the ChartObjects collection to call the following properties and methods:

Unlike in previous version, the ChartObjects collection can now read the the properties for height, width, left and top.

Use the method to create a new, empty embedded chart and add it to the collection. Use the method to add data and format the new chart. The following example creates a new embedded chart and then adds the data from cells A1:A20 as a line chart.

Visual Basic for Applications
Dim ch As ChartObject Set ch = Worksheets("sheet1").ChartObjects.Add(100, 30, 400, 250) ch.Chart.ChartWizard source:=Worksheets("sheet1").Range("a1:a20"), _ gallery:=xlLine, title:="New Chart"

Use ChartObjects(), where is the embedded chart index number or name, to return a single object. The following example sets the pattern for the chart area in embedded Chart 1 on the worksheet named "Sheet1."

Visual Basic for Applications
Worksheets("Sheet1").ChartObjects(1).Chart. _ CChartObjecthartArea.Format.Fill.Pattern = msoPatternLightDownwardDiagonal 
Chart Objects Collection Object ChartObject Collection ChartObject Collection Object

See also:

index index