VBA & Macro Problems

How to Create a VBA Before-Close Confirmation Dialog in PowerPoint

Khadija KhanKhadija Khan Nov 2, 2026 870 views

Question details

The user wants to display a pop-up confirmation message before closing a PowerPoint presentation, allowing users to cancel the close operation if certain conditions are not met.

How to Create a Before-Close Confirmation Dialog in PowerPoint VBA
Product
Microsoft PowerPoint
Device & OS
not provided
Scenario
A user needs to prompt for confirmation upon attempting to close an individual presentation, rather than the entire application, preventing data loss if tasks like uploading data are incomplete.
Observed behavior
Standard close event macros often trigger when the entire application closes rather than an individual presentation, and standard modules cannot natively capture presentation-level close events with a cancellation parameter.
Before you start

Ensure that the Developer tab is enabled in your PowerPoint ribbon to access the VBA Editor. Implementing this solution requires basic familiarity with VBA, specifically creating and calling Class Modules.

Solution 1Recommended

Implement the App_PresentationBeforeClose Event in a Class Module

Use a custom class module to listen for application-level events, allowing you to intercept the presentation's close action and provide a cancelable prompt.

Unlike Excel or Word, PowerPoint does not have built-in document-level events like 'BeforeClose' directly accessible in standard modules. To intercept a presentation closing, you must configure an Application-level event listener using a Class Module.

1
Create a Class Module

Press Alt + F11 to open the VBA Editor. Go to Insert > Class Module. In the Properties window (F4), rename the new class module to 'EventClassModule'.

2
Declare the Application Event

In the 'EventClassModule' code window, add the following line at the very top: Public WithEvents App As Application

3
Write the Event Code

Select 'App' from the left-side dropdown above the code window, and 'PresentationBeforeClose' from the right-side dropdown. Within the generated subroutine, insert the following code: If MsgBox("Have you uploaded the data?", vbQuestion + vbYesNo + vbDefaultButton2, "Attention") = vbNo Then Cancel = True

4
Initialize the Event Listener

Go to Insert > Module to create a standard module. Declare a global instance of your class by typing: Dim X As New EventClassModule. Then, create an initialization macro: Sub InitializeAppEvents() \n Set X.App = Application \n End Sub

5
Run the Initialization Macro

Run the 'InitializeAppEvents' macro. Your PowerPoint application is now actively listening for the close event and will trigger the confirmation prompt when you try to close the file.

Implement the App_PresentationBeforeClose Event in a Class Module
Macro Initialization: The event listener only works after the initialization macro is run. To automate this, you can call the initialization macro from an Auto_Open routine or via a custom Ribbon onLoad callback.
Advanced Presentation Management

Use WPS Presentation for Seamless VBA Integration

WPS Office offers robust VBA support, allowing you to create complex macros, manage application events, and automate your presentation workflows efficiently and securely.

  1. 1. Open WPS Presentation: Launch WPS Office and open your presentation document.
  2. 2. Access the VBA Editor: Navigate to the 'Tools' or 'Developer' tab and click on 'VBA Editor' (or press Alt + F11).
  3. 3. Insert Modules and Code: Use the project explorer to insert Class Modules and standard Modules, applying the exact same VBA event code as you would in standard Office setups.
  4. 4. Save as Macro-Enabled: Go to Menu > Save As, and choose 'PowerPoint Macro-Enabled Presentation (*.pptm)' to preserve your event listeners.
Fully compatible with Microsoft PowerPoint VBA macros and file formats (.pptm).Supports advanced slide and presentation event triggers through Class Modules.Lightweight architecture ensures fast macro execution without application lag.Completely free to use with a highly familiar and intuitive ribbon interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does PowerPoint VBA lack a simple Document_BeforeClose event?

PowerPoint's VBA object model handles events primarily at the Application level rather than the Document level. This architectural difference requires developers to use Class Modules with 'WithEvents' declarations to capture actions like opening, saving, or closing individual presentations.

How can I make the event listener start automatically when the file opens?

You can automatically trigger your initialization subroutine by creating a macro named 'OnAutoOpen' (in a macro-enabled add-in) or by attaching the initialization script to a Ribbon customization using the 'onLoad' callback. Note that PowerPoint does not support the 'Auto_Open' macro in standard presentations the way Excel does.

What file format is required to save presentations with VBA events?

To retain any VBA code, including standard modules and Class Modules, you must save your file as a PowerPoint Macro-Enabled Presentation (.pptm) or a PowerPoint Macro-Enabled Show (.ppsm). Saving as a standard .pptx will permanently remove all macros from the file.