logo
search
VBA & Macro Problems

How to Create a Non-Blocking Wait Function in PowerPoint VBA

Maira MehtabMaira Mehtab Sep 22, 2026 869 views

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.
Before you start

Ensure that your presentation is saved as a Macro-Enabled Presentation (.pptm) before adding or testing any VBA scripts.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 while in PowerPoint to open the Visual Basic for Applications (VBA) editor window.

2
Insert a New Module

Right-click on your presentation in the Project Explorer pane on the left, select Insert, and click Module.

3
Add the Wait Function

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

4
Call the 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.

CPU Usage Warning: While this method prevents the application from freezing, continuous looping still consumes CPU resources. It is best used for very short delays.
Efficient Presentation Macros

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. 1. Open WPS Presentation: Launch WPS Office and open your macro-enabled presentation file.
  2. 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. 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. 4. Run Your Macro: Click Macros, select your newly created script, and hit Run to execute the code smoothly.
Fully compatible with Microsoft PowerPoint (.pptm) filesBuilt-in robust VBA editor for creating and debugging codeLightweight design ensures smoother macro executionFree to download and use for daily office tasks
microsoft office alternative - wps office

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.