How to Create a Non-Blocking Wait Function in PowerPoint VBA
Question details
The user needs to create a wait function in PowerPoint VBA that pauses execution for a set time without freezing the application or causing high CPU usage.
- Product
- PowerPoint
- Device & OS
- not provided
- Scenario
- Building a VBA game or running interval-based updates where a timed pause is required.
- Observed behavior
- Standard continuous loops cause the application to lag, freeze, and consume excessive CPU resources.
Ensure that your presentation is saved as a Macro-Enabled Presentation (.pptm) before adding or testing any VBA scripts.
Use a DoEvents Loop to Yield Control
A simple loop incorporating the DoEvents function allows PowerPoint to process background tasks and UI updates while waiting for the timer to finish.
Press Alt + F11 while in PowerPoint to open the Visual Basic for Applications (VBA) editor window.
Right-click on your presentation in the Project Explorer pane on the left, select Insert, and click Module.
Paste the following code into the module window: Function Wait(seconds As Single) Dim startTime As Single startTime = Timer Do While Timer < startTime + seconds DoEvents Loop End Function
In your main macro or game loop, call the wait function (e.g., Wait 2) to introduce a 2-second pause without locking up the user interface.
Implement Windows API Timers for Event-Driven Delays
For longer delays or complex games, replacing busy-waiting loops with Windows API timers reduces CPU usage significantly and creates a true event-driven architecture.
Create and Run VBA Macros Seamlessly in WPS Office
WPS Presentation provides excellent support for VBA macros, allowing you to run your scripts, games, and automation workflows efficiently. It offers a lightweight environment that minimizes CPU usage.
- 1. Open WPS Presentation: Launch WPS Office and open your macro-enabled presentation file.
- 2. Access the Developer Tools: Navigate to the Developer tab on the top ribbon. If it is not visible, you can enable it from the Options menu.
- 3. Launch the VBA Editor: Click on the Visual Basic icon to open the VBA editor and paste or write your custom Wait functions.
- 4. Run Your Macro: Click Macros, select your newly created script, and hit Run to execute the code smoothly.

Frequently Asked Questions
Why does PowerPoint freeze when I use the Sleep function in VBA?
The Sleep function pauses the entire application thread, preventing PowerPoint from updating the screen or registering mouse clicks. Using a non-blocking wait function that includes DoEvents resolves this freezing by yielding control back to the operating system momentarily.
Can I use Application.OnTime in PowerPoint VBA like I do in Excel?
No, PowerPoint VBA does not natively support the Application.OnTime method. You must use alternative approaches such as custom loops with DoEvents or Windows API timers (SetTimer) to achieve scheduled delays.
Does leaving DoEvents loops running cause high CPU usage?
Yes. While a DoEvents loop prevents the UI from freezing, the VBA code is still constantly running to evaluate the current time against the end time. This continuous processing consumes CPU resources, which is why API timers are recommended for more complex projects.




