Office Settings & Configuration

Assign a VBA Macro to an Existing PowerPoint Shape

Steve KSteve K Nov 18, 2026 872 views

Question details

Assign a VBA macro to an existing PowerPoint shape, or to multiple shapes at once.

Assign a VBA Macro to an Existing PowerPoint Shape
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.
Before you start

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.

Solution 1Recommended

Assign a Macro to Selected Shapes with VBA

Use ActionSettings to apply the same click action to one or more selected shapes.

1
Select the shapes

On the slide, select one shape or hold the selection key and select multiple shapes.

2
Add the assignment code

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

3
Run the assignment

Return to the slide with the shapes selected, open Developer > Macros, select AssignMacroToSelectedShapes, and click Run.

4
Test the action

Start Slide Show > From Current Slide and click a selected shape to test the assigned macro.

Assign a Macro to Selected Shapes with VBA
Use a mouse-over action instead: Replace ppMouseClick with ppMouseOver in the code to run the macro when the pointer moves over the shape during the slide show.
Free Microsoft Office alternative

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.

Open and edit Microsoft PowerPoint PPTX filesWork with shapes and other slide objects in WPS PresentationUse a familiar interface for a smoother transition from Microsoft OfficeCreate and edit presentations with a free, lightweight office suite
QA img-9

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.