top of page
Tutorial
Run Loop On Slide Show Begin
The problem
When making a PowerPoint game that initiates with a loop, you may stumble upon a problem. You can use OnSlideShowPageChange to detect when the slide show starts and then call the macro that executes the loop. This method, however simple, imposes a problem – when exiting the slide show, PowerPoint hangs and then crashes.
The solution
This quick and easy tutorial proposes a very simple yet effective solution to this problem. It still uses OnSlideShowPageChange, but instead of calling the loop macro from here, it actually initializes the App variable. This variable has an event called SlideShowNextSlide which fires when the slide is shown.
Below is the all the code needed for this solution. Feel free to use it on any of your projects.
1
2
3
4
5
6
7
8
9
10
11
12
Private WithEvents App As Application
Private Initialized As Boolean
Sub OnSlideShowPageChange()
If Not Initialized Then Set App = Application
End Sub
Private Sub App_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
Initialized = True
Set App = Nothing
AppLoop ' Your macro that runs a loop
End Sub
Solution explanation
The Application object has the SlideShowNextSlide event which is very useful for what we want to achieve. However, in order for the event to work, the object (App in this case) must be initialized. To initialize the object we use OnSlideShowPageChange. The Initialized variable is there to prevent this code to run everytime you navigate to a different slide, since we only want this to run when we enter the slide show.
bottom of page