VBA 计数图表对象中的系列数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13363812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 14:24:41  来源:igfitidea点击:

VBA Count number of series in a chartObject

vbaexcel-vbaexcel-2010excel

提问by harryg

I know this seems straightforward but it doesn't seem to work for me. I have a chart on "Sheet1". It is the only chart on the sheet. I want to get the number of series in the chart. So I use:

我知道这看起来很简单,但它似乎对我不起作用。我在“Sheet1”上有一张图表。它是工作表上唯一的图表。我想获取图表中的系列数。所以我使用:

Debug.Print ThisWorkbook.Sheets("Sheet1").ChartObjects(1).SeriesCollection.Count

to get the answer in the immediate window. However VBA gives me a "Object doesn't support property or method" error. Any ideas?

在即时窗口中获得答案。但是 VBA 给了我一个“对象不支持属性或方法”的错误。有任何想法吗?

回答by Alex P

You need to add in Chart:

您需要添加Chart

Debug.Print ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection.Count

回答by deusxmach1na

Try this Debug.Print ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection.Count

尝试这个 Debug.Print ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection.Count