有时,当我更改图形数据时,excel 中的趋势线标签没有更新。因此我想通过 VBA 更新。我想对所有工作表和图表中的所有现有趋势线执行此操作。
到目前为止,我的代码不起作用。你会在评论中发现错误。
Sub Auto_Open()
Debug.Print "Start"
Dim oChart As ChartObject, nSheet As Integer, nChart As Integer
nSheet = 1
Do While nSheet <= Sheets.Count
nChart = 1
Do While nChart <= Sheets(nSheet).ChartObjects.Count
nSeriesCollection = 1
'Debug.Print Sheets(nSheet).ChartObjects(nChart).SeriesCollection.Count
'Error in next line
Do While nSeriesCollection <= Sheets(nSheet).ChartObjects(nChart).SeriesCollection.Count
Debug.Print "nSheet: " & nSheet & " nChart: " & nChart
Set oChart = Sheets(nSheet).ChartObjects(nChart)
oChart.Activate
'Next line has to changed too
ActiveChart.SeriesCollection(1).Trendlines(1).Select
With Selection
.DisplayRSquared = False
.DisplayEquation = False
.DisplayRSquared = True
.DisplayEquation = True
End With
nSeriesColletion = nSeriesColletion + 1
Loop
nChart = nChart + 1
Loop
nSheet = nSheet + 1
Loop
End Sub
########################################################################
存在运行时错误“438”。错误注释所在行中的对象不支持此属性或方法。