Excel 从ChartObjects获取图表标题

Excel 从ChartObjects获取图表标题,excel,vba,excel-charts,Excel,Vba,Excel Charts,我希望能够通过标题或其他非默认名称来识别图表。如果它有某个标题,我将尝试将其删除: Sub delchart() Call create_chart Dim d For Each d In Worksheets("sheet1").ChartObjects Debug.Print d.Name '<-not a usable name If d.ChartTitle = "Scatter Chart" Then '<- errors d.Del

我希望能够通过标题或其他非默认名称来识别图表。如果它有某个标题,我将尝试将其删除:

Sub delchart()

Call create_chart
Dim d

For Each d In Worksheets("sheet1").ChartObjects

    Debug.Print d.Name '<-not a usable name

    If d.ChartTitle = "Scatter Chart" Then '<- errors
        d.Delete
    End If
Next d
End Sub
如果图表具有我提供的特定标识,我如何删除该图表?图表标题对我来说是最直观的,但似乎无法通过ChartObject访问标题。

您可以像这样访问ChartTitle文本:

Sub delchart()

Call create_chart
Dim d

For Each d In Worksheets("sheet1").ChartObjects

    Debug.Print d.Name '<-not a usable name

    If d.Chart.ChartTitle.Caption = "Scatter Chart" Then
        d.Delete
    End If
Next d

End Sub
Sub delchart()

Call create_chart
Dim d

For Each d In Worksheets("sheet1").ChartObjects

    Debug.Print d.Name '<-not a usable name

    If d.Chart.ChartTitle.Caption = "Scatter Chart" Then
        d.Delete
    End If
Next d

End Sub