Assign a VBA Macro to an Existing PowerPoint Shape
Question details
Assign a VBA macro to an existing PowerPoint shape, or to multiple shapes at once.

- Product
- Microsoft PowerPoint
- Device & OS
- not provided
- Scenario
- A presentation author wants a shape to run a macro when clicked or when the pointer moves over it during a slide show.
- Observed behavior
- The chosen shape action runs the specified macro during the slide show.
Open the presentation in desktop PowerPoint and make sure the macro is a public, parameterless Sub in a standard VBA module. Save the presentation as a macro-enabled PowerPoint Presentation (.pptm), and enable macros only if you trust the file.
Assign a Macro to Selected Shapes with VBA
Use ActionSettings to apply the same click action to one or more selected shapes.
On the slide, select one shape or hold the selection key and select multiple shapes.
Open Developer > Visual Basic, choose Insert > Module, and add this code. Replace MyMacroName with the name of your existing macro: Public Sub AssignMacroToSelectedShapes() Dim shp As Shape For Each shp In ActiveWindow.Selection.ShapeRange With shp.ActionSettings(ppMouseClick) .Run = "MyMacroName" .Action = ppActionRunMacro End With Next shp End Sub
Return to the slide with the shapes selected, open Developer > Macros, select AssignMacroToSelectedShapes, and click Run.
Start Slide Show > From Current Slide and click a selected shape to test the assigned macro.

Assign a Macro to a Shape with the Action Dialog
Use PowerPoint's Action dialog when you want to assign an available macro without writing assignment code.
Edit PowerPoint Presentations with WPS Office
WPS Office is a free, lightweight alternative for creating and editing presentations. Its familiar interface and PowerPoint format compatibility make it easy to move existing slides into WPS Presentation. Use Microsoft PowerPoint for the VBA-specific shape action described above.

Frequently Asked Questions
Can I assign the same macro to several shapes at once?
Yes. Select the shapes on the slide and run a VBA procedure that loops through ActiveWindow.Selection.ShapeRange, assigning the macro through each shape's ActionSettings.
How do I run the macro when I hover over a shape?
Use ActionSettings(ppMouseOver) in VBA, or select the shape and choose Insert > Action > Mouse Over > Run macro.
Why doesn't the macro run when I click the shape while editing?
A shape's click action is intended to run in Slide Show view. Choose Slide Show > From Current Slide and test the shape there.
What file format should I use to keep the VBA code?
Choose File > Save As and select PowerPoint Macro-Enabled Presentation (.pptm). Enable macros only when you trust the presentation.
Why isn't my macro listed in the Action dialog?
Check in Developer > Visual Basic that the macro is a public Sub with no parameters in a standard module, and confirm that macros are enabled for the trusted presentation.




