How do I reference charts with the same name, but on different worksheets?

后端 未结 3 709
渐次进展
渐次进展 2021-01-04 10:32

I have two worksheets containing charts, and use a macro to run over all the sheets with charts in them and update the values charted.

However, I run into a problem

3条回答
  •  感动是毒
    2021-01-04 10:48

    There is a difference between Chart and Worksheet.ChartObject.Chart.

    Make it clear that

    • When you create a chart in a worksheet, Excel creates a ChartObject to contain the Chart. So the Chart is a child of ChildObject which in turn is a child of Worksheet.
    • When you create a chart as a sheet, it is a Chart (or you may call it "chart sheet") equivalent to a Worksheet.

    Therefore a Worksheet.ChartObject.Chart is different from a Chart sheet in the following way:

    • A Chart from Worksheet.ChartObject.Chart contains all the properties of a chart.
    • A Chart sheet contains all the properties of a chart AND some properties of a sheet.

    So the .Name property is supposed to be for Chart sheet but not for Worksheet.ChartObject.Chart.

    I'd say the additional display of the activesheet name when calling ChartObject.Chart.Name is not a bug but a debugged bug. ChartObject.Chart wouldn't and shouldn't have a Name in the first place. You can call ChartObject.Chart.Name because there is an overlapping in the intellisense for object model of Chart. Had Microsoft hasn't allow for this, there would be a bug.

    So in short, remember that a chart has no name, it is the ChartObject or the Sheet that carries the name. To contrast this, a chart has ChartTitle.

提交回复
热议问题