A Next Slide button that runs code also
Sometimes you want to do something automatically when a user changes slides, or you need a way to force some macro code to run automatically when a user starts a slide show. Or you might need to initialize an event handler at the start of a slide show without having to resort to an add-in.
If you can write macro code to do the "something", you're halfway there. The trick is to force the code to run "automatically" when you start the presentation. Or at least to appear to.
PowerPoint won't run code from a presentation automatically, but you can start the presentation with an introductory slide. On it, you can place a "Start The Show" button. Give the button an action setting of Run Macro and have it run GoToNextSlide (code below). Modify GoToNextSlide to initialize your event handler.
Sub GoToNextSlide() ' Instead of a normal Next Slide action button ' have your Next Slide action = Run Macro and have it ' run this instead. ' ' This runs any additional code you like and then ' goes to the next slide ' add whatever code you like here or better yet, ' put it in a separate subroutine and call it from here ' for example: Call ExampleCode With ActivePresentation.SlideShowWindow .View.GotoSlide (ActivePresentation.SlideShowWindow.View.Slide.SlideIndex + 1) End With ' or add code here, after you've moved to the next slide Call ExampleCode End Sub Sub ExampleCode() MsgBox ActivePresentation.SlideShowWindow.View.Slide.SlideIndex End Sub
See How do I use VBA code in PowerPoint? to learn how to use this example code.