How to Fix Loop without Do Error in PowerPoint VBA Live Clock
Question details
The user is trying to display a live clock on every PowerPoint slide using a VBA macro but encounters a 'Loop without Do' compile error after adding a second loop. They also need the macro to run automatically.

- Product
- PowerPoint
- Device & OS
- not provided
- Scenario
- Creating a VBA macro to continuously update a live clock across multiple slides during an active presentation.
- Observed behavior
- The VBA macro fails to compile, throwing a 'Loop without Do' error due to improperly paired or nested loop structures. Additionally, the macro requires manual execution before starting the slideshow.
Ensure you save your presentation as a Macro-Enabled Presentation (.pptm) to prevent losing your VBA code when closing the file.
Correctly Pair VBA Loops and With Statements
Resolve the compile error by ensuring every Do has a matching Loop, every For has a matching Next, and nested statements are properly closed.
The 'Loop without Do' error often occurs when statements inside the loop, such as a 'With' block or an inner 'For...Next' loop, are not correctly closed before the outer loop finishes. The VBA compiler gets confused by the improper nesting and throws this error.
Press Alt + F11 in PowerPoint to open the VBA Editor and locate your live clock macro.
If you are using a 'With' block to format the clock text (e.g., With ActivePresentation.Slides(i)...), ensure you add 'End With' before the 'Next i' statement.
Check your loop sequence. If you use a 'Do Until' loop containing a 'For...Next' loop to update slides, make sure the 'Next' statement appears before the 'Loop' statement.

Automate the Macro Execution
Set up your PowerPoint file to trigger the clock macro automatically when the file or slideshow opens.
Try WPS Office for Seamless Presentation Management
If you frequently work with macros, presentations, and complex document formatting, WPS Office provides a lightweight, highly compatible, and cost-effective alternative to Microsoft Office.
- 1. Download WPS Office: Visit the official WPS website to download and install the free WPS Office suite.
- 2. Open Your Presentation: Launch WPS Presentation and open your existing .pptx or .pptm files directly without conversion.
- 3. Edit and Present: Enjoy full editing capabilities and present your slides with seamless format compatibility.

Frequently Asked Questions
Why do I get a 'Loop without Do' error in VBA?
This compile error occurs when a loop structure is improperly nested or missing its closing statement. It frequently happens if you forget an 'End With' or an 'End If' inside a loop, causing the compiler to misread the 'Loop' or 'Next' statement.
Do I need to use With/End With in my VBA clock macro?
No, it's not strictly necessary. However, it is highly recommended when applying multiple properties (like Text, Font Color, and LanguageID) to the exact same shape object, as it makes the code much cleaner and slightly improves performance.
Can a PowerPoint VBA macro run automatically when opened?
PowerPoint does not automatically run macros upon opening a standard file due to security restrictions. To fully automate a macro upon opening, you generally need to convert your code into a PowerPoint Add-in and utilize AutoOpen events.




