我有一个函数,我希望将图表对象作为参数传递,但我无法这样做。我在调用函数
时收到以下消息 runtime error 438: Object does not support this property or method.
以下是我正在处理的代码集。
Sub testppt()
changeChart (Application.ActivePresentation.Slides(4).Shapes(1).Chart)
changeChart (Application.ActivePresentation.Slides(5).Shapes(1).Chart)
changeChart (Application.ActivePresentation.Slides(6).Shapes(1).Chart)
changeChart (Application.ActivePresentation.Slides(7).Shapes(1).Chart)
changeChart (Application.ActivePresentation.Slides(8).Shapes(1).Chart)
End Sub
Function changeChart(chartToChange As Object)
Dim curSeries As Object
Dim curPoint As Object
For Each curSeries In chartToChange.SeriesCollection
With curSeries
For Each curPoint In .Points
If curPoint.DataLabel.Text < 0 Then
curPoint.DataLabel.Text = curPoint.DataLabel.Text * (-1)
End If
If curPoint.DataLabel.Text < 20 Then
curPoint.DataLabel.Delete
End If
Next
End With
Next
End Function
答案 0 :(得分:2)
正如我在评论中提到的,删除括号:
Sub testppt()
changeChart Application.ActivePresentation.Slides(4).Shapes(1).Chart
changeChart Application.ActivePresentation.Slides(5).Shapes(1).Chart
changeChart Application.ActivePresentation.Slides(6).Shapes(1).Chart
changeChart Application.ActivePresentation.Slides(7).Shapes(1).Chart
changeChart Application.ActivePresentation.Slides(8).Shapes(1).Chart
End Sub
或使用Call
关键字:
Sub testppt()
Call changeChart(Application.ActivePresentation.Slides(4).Shapes(1).Chart)
Call changeChart(Application.ActivePresentation.Slides(5).Shapes(1).Chart)
Call changeChart(Application.ActivePresentation.Slides(6).Shapes(1).Chart)
Call changeChart(Application.ActivePresentation.Slides(7).Shapes(1).Chart)
Call changeChart(Application.ActivePresentation.Slides(8).Shapes(1).Chart)
End Sub