Partilhar via


Chart.ChartObjects Method

Gets an object that represents either a single embedded chart (a ChartObject object) or a collection of all the embedded charts (a ChartObjects object) on the sheet.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

'Declaration
Function ChartObjects ( _
    Index As Object _
) As Object
Object ChartObjects(
    Object Index
)

Parameters

  • Index
    Type: System.Object

    The name or number of the chart. This argument can be an array, to specify more than one chart.

Return Value

Type: System.Object
An object that represents either a single embedded chart (a ChartObject object) or a collection of all the embedded charts (a ChartObjects collection) on the sheet.

Remarks

This method is not equivalent to the Charts property. This method returns embedded charts; the Charts property returns chart sheets. Use the Chart property to return the Chart object for an embedded chart.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example creates a Chart and then uses the ChartObjects method to display whether or not the chart was created by Microsoft Office Excel.

Private Sub UseChartObjects()
    Me.Range("A1", "A5").Value2 = 22
    Me.Range("B1", "B5").Value2 = 55

    Dim Chart1 As Microsoft.Office.Tools.Excel.Chart = _
        Me.Controls.AddChart(Me.Range("D2", "H12"), "Chart1")

    Chart1.SetSourceData(Me.Range("A1", "B5"), Excel.XlRowCol.xlColumns)
    Chart1.ChartType = Excel.XlChartType.xlColumnClustered

    Dim chartObjects1 As Excel.ChartObjects = _
        CType(Chart1.ChartObjects(), Excel.ChartObjects)

    If chartObjects1.Creator = Excel.XlCreator.xlCreatorCode Then
        MsgBox("The ChartObjects was created by Microsoft Office Excel.")
    End If 

End Sub
private void UseChartObjects()
{
    this.Range["A1", "A5"].Value2 = 22;
    this.Range["B1", "B5"].Value2 = 55;

    Microsoft.Office.Tools.Excel.Chart chart1 =
        this.Controls.AddChart(this.Range["D2", "H12"], 
        "chart1");

    chart1.SetSourceData(this.Range["A1", "B5"], 
        Excel.XlRowCol.xlColumns);
    chart1.ChartType = Excel.XlChartType.xlColumnClustered;

    Excel.ChartObjects chartObjects1 =
        (Excel.ChartObjects)chart1.ChartObjects();

    if (chartObjects1.Creator == Excel.XlCreator.xlCreatorCode)
    {
        MessageBox.Show("The ChartObjects was created by " +
            "Microsoft Office Excel.");
    }
}

.NET Framework Security

See Also

Reference

Chart Interface

Microsoft.Office.Tools.Excel Namespace