People often ask "How do I make this macro run every time I show a new slide or add a new slide etc." This means making PowerPoint respond to that EVENT and, unlike in Excel, it's not that easy!
First, I would avoid using the pseudo events left over from version 97, e.g., Sub OnSlideShowpageChange. Pseudo events are not properly supported in later versions of PowerPoint and so will work erratically.
Also, naming your sub Auto_Open will not work in a standard presentation but will in a PPA (version 97-2003) or a PPAM (version 2007/2010) AddIn.
So, let's create a simple AddIn...
1. Add a Class
In the VB editor INSERT >> CLASS MODULE
If the properties window isn't already visible, press F4 or View > Properties window to show it. Use this to rename the class module to something more memorable. We used cNewSlideClass
Add the code:
Public WithEvents PPTEvent As Application
2. Create an Object Based on the Class
Insert a standard module (INSERT >> MODULE) and declare the object
(change the names as appropriate)
Public objNewSlide as New cNewSlideClass
3. Initialise the Object
In the normal module create a new sub call Auto_Open. Remember this will only fire in an AddIn and only when the AddIn loads.
Add the code as below:
objNewSlide.PPTEVENT = Application
4. The Event
Back in the class module you will see two drop down menus at the top of the page.
Change the left one to PPTEVENT
; the right, select the event to fire your macro. In our case PresentationNewSlide
Between the lines of code auto inserted add the code you want to run.
Here is ours:
Private Sub PPTEvent_PresentationNewSlide(ByVal Sld As Slide)
MsgBox "You inserted slide " & Sld.SlideIndex
Not that useful, but just an example!
Finally save as a PPA or PPAM AddIn, depending on your version, and you're good to go!