excel:获取当前图表的索引
我创build一个新的图表
Sheets("DatenFilledChart").Select ActiveSheet.Shapes.AddChart.Select ActiveChart.ChartType = xlArea ActiveChart.SetSourceData Source:=Range("DatenFilledChart!$B$4:$B$1004") ActiveChart.SeriesCollection(1).XValues = "=DatenFilledChart!$A$4:$A$1004" ActiveChart.SeriesCollection(1).Name = "=DatenFilledChart!$B$1"
为了与当前的图表工作,我想保存它的索引
indexOfChart = ActiveChart.Index
但是,失败
方法Index对象_Chart无效
我究竟做错了什么?
尝试使用这个:
indexOfChart = Shapes.Count
代替
indexOfChart = ActiveChart.Index
Index
属性不适用于图表集合:
索引属性
页面集合中的Tab对象的位置或Pages集合中的Page对象的位置。
阅读更多信息: http : //msdn.microsoft.com/en-us/library/office/ff194426.aspx
索引是ChartObject类的一个属性。
Chart是ChartObject类的成员。
因此,当你使用一个Chart对象时,你必须像这样在一个等级上升:
indexOfChart = ActiveChart.Parent.Index
由于AddChart
返回对添加对象的引用,最简单的方法就是使用该引用。
Sub tester() Dim co As Shape Set co = Sheet1.Shapes.AddChart() With co.Chart .ChartType = xlArea .SetSourceData Source:=Range("Sheet1!$A$1:$B$5") .SeriesCollection(1).Name = "Testing" 'etc etc End With End Sub