How to Hide an Object After Clicking on Another Slide in PowerPoint VBA
Question details
The user wants to know how to reliably reference slides and shapes in PowerPoint VBA to hide or reveal an object, such as a smiley face, after a correct answer is clicked during a presentation game.

- Product
- PowerPoint
- Device & OS
- not provided
- Scenario
- Creating an interactive PowerPoint game where clicking an object or slide triggers a VBA macro to reveal or hide an object on a different slide.
- Observed behavior
- Needs a stable method to reference slides and shapes so the macro doesn't break if new slides are inserted into the presentation.
Ensure that the Developer tab is enabled in your PowerPoint ribbon so you can access the Visual Basic Editor and insert standard modules.
Use SlideIDs to Reference Slides in a Standard VBA Module
SlideIDs are permanent and do not change even if you add or rearrange slides. This is the most reliable method for referencing a slide in your macro.
While Slide Indexes (e.g., Slides(2)) are simple to use for fixed presentations, they will break your macro if you insert a new slide before the target. SlideIDs remain stable after creation.
Additionally, ensure your code is placed in a standard VBA module rather than a slide code module, unless the slide specifically contains ActiveX controls.
Press ALT + F11 on your keyboard to open the VBA Editor in PowerPoint.
Click 'Insert' in the top menu bar, then select 'Module' to create a standard code module.
Create your macro and reference the specific SlideID and Shape name. For example: ActivePresentation.Slides.FindBySlideID(256).Shapes("SmileyFace").Visible = msoTrue
Go back to your presentation, select the object or text you want to act as the trigger, click 'Insert' > 'Action', and choose 'Run Macro' to select your newly created script.

Reference Slides by Assigning Custom Names
If you prefer using names over SlideIDs, you can assign custom names to your slides using a one-time VBA code execution.
Looking for a Free Alternative to PowerPoint?
If you are dealing with complex PowerPoint VBA issues, consider trying WPS Office. It provides a lightweight, free, and highly compatible presentation tool that handles animations and triggers intuitively, often without the need for complex code.
- 1. Download and Install WPS Office: Visit the official WPS website to download the free installation package and follow the on-screen instructions.
- 2. Open Your Presentation: Launch WPS Presentation and open your existing .pptx file. Your formats and layouts will be preserved seamlessly.
- 3. Set Up Interactive Triggers: Use the built-in animation triggers in WPS Presentation to create interactive reveal games without writing any VBA code.

Frequently Asked Questions
Why does my VBA macro break when I add a new slide?
If you use Slide Indexes (such as Slides(2)), the index number shifts when you insert a new slide before it. Using SlideIDs (via FindBySlideID) ensures a permanent reference that doesn't break when rearranging slides.
How do I find the SlideID of a specific slide?
You can find a slide's ID by selecting the slide and running a quick macro or typing '? ActiveWindow.View.Slide.SlideID' in the VBA Immediate Window (CTRL + G).
Do I need to put my macro in a Slide Code Module?
No. Unless your slide contains specific ActiveX controls that require event-driven code, it is best practice to place your presentation macros in a standard VBA module.
How do I find the name of the shape I want to hide?
In PowerPoint, go to the 'Home' tab, click 'Select' in the Editing group, and choose 'Selection Pane'. This panel lists all objects on the slide, allowing you to view and change their names for your VBA macro.




