共用方式為


Chart.ChartObjects(Object) Method

Definition

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.

public object ChartObjects (object Index);
abstract member ChartObjects : obj -> obj
Public Function ChartObjects (Optional Index As Object) As Object

Parameters

Index
Object

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

Returns

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.

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 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.");
    }
}
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

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.

Applies to