Sa Jona
Sa Jona

Reputation: 3

VBA - Powerpoint - Handling onClick Event

I am developing a macro for PowerPoint in vba

My goal is to have one single Sub that 1-6 shapes were manually assigned to.

So the sub is executed when a shape is clicked and should determine with a Select case statement which of the shapes was clicked exactly (and therefore run a specific script)

I am struggeling to find Code snippets that show how the onclick event is handled and how I can determine for which shape the „onclick is True“

Can you guys help me with this? Thanks in advance!

Upvotes: 0

Views: 2123

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

If you assign the following macro to each of the clickable shapes, it'll do what you're after in Slide Show view. Select the shape, choose Insert | Action and choose run Macro: HandleShapeClick.

You may need to modify it to run on Macs because of a bug in the VBA implementation there.

If you need something like this to function in Normal or Slide view, you'll need entirely different (and considerably more complex) code.

Sub HandleShapeClick(oSh As Shape)

    Select Case oSh.Name
        Case Is = "Rectangle 3"
            MsgBox "You clicked Rectangle 4"
        Case Is = "Rectangle 4"
            MsgBox "You clicked Rectangle 5"
        Case Is = "Rectangle 5"
            MsgBox "You clicked Rectangle 3"
        ' etc, for each add'l clickable shape
        
    End Select
    
End Sub

Upvotes: 2

Related Questions