Question

I have a function in which I want to pass a chart object as a parameter but I am not able to do so. I am getting the below message while calling the function

runtime error 438: Object does not support this property or method.

Below is the set of code I am working on.

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
Was it helpful?

Solution

As I metnioned in comments, remove parentheses:

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

or use Call keyword:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top