Kusa Shaha
Kusa Shaha

Reputation: 112

If statement for ppActionRunMacro

If ActivePresentation.Slides(1).Shapes("Rectangle 5").ActionSettings(ppMouseClick).Action = ppActionRunMacro(CorrectAnswer) Then
MsgBox "YEET"
End If

How do I make a MsgBox pop-up if a certain shape has a certain macro to it?

Upvotes: 2

Views: 272

Answers (2)

Bhavesh Shaha
Bhavesh Shaha

Reputation: 783

Your syntax is causing you the error.

Following is the correct syntax:

.ActionSettings.(ppMouseClick).Run = "CorrectAnswer"

Upvotes: 1

PeterT
PeterT

Reputation: 8557

If your rectangle's ActionSettings are set like this

Sub Setup()
    Dim ppt As Presentation
    Set ppt = ActivePresentation

    With ppt.Slides(1).Shapes("Rectangle 3").ActionSettings(ppMouseClick)
        .Action = ppActionRunMacro
        .Run = "CorrectAnswer"
    End With
End Sub

Public Sub CorrectAnswer()
    Debug.Print "show the correct answer"
End Sub

Then you can detect which shape has the macro you're looking for with

Sub test()
    Dim ppt As Presentation
    Set ppt = ActivePresentation

    Dim sld As Slide
    For Each sld In ppt.Slides
        Dim shp As Shape
        For Each shp In sld.Shapes
            If shp.Name Like "Rectangle*" Then
                If shp.ActionSettings(ppMouseClick).Run = "CorrectAnswer" Then
                    MsgBox "YaYaYeet"
                End If
            End If
        Next
    Next sld
End Sub

Upvotes: 2

Related Questions