PowerPoint Events

John WilsonCEO PowerPoint Alchemy
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

A. In the VB editor INSERT >> CLASS MODULE

B. 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.

C. Add the code:
Public WithEvents PPTEvent As Application

Open in new window

2. Create an Object Based on the Class

A. Insert a standard module (INSERT >> MODULE) and declare the object

B. (change the names as appropriate)
Public objNewSlide as New cNewSlideClass

Open in new window

3. Initialise the Object

A. 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.

B. Add the code as below:
Sub Auto_Open()
                          objNewSlide.PPTEVENT = Application
                      End Sub

Open in new window

4. The Event

A. 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.

B. 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
                      End Sub

Open in new window

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!
John WilsonCEO PowerPoint Alchemy

Comments (1)

Jamie Garroch (MVP)PowerPoint Technical Consultant

This is a great article JSRWilson. I'd just like to add that if a developer is looking for a cross-platform compatible solution for application events that will work on PC and Mac versions of PowerPoint, there doesn't appear to be one. Why?

Application Events are supported by PC versions of PowerPoint only (as of PowerPoint:mac 2011, and possible PowerPoint:mac 2016)
Psuedo Events are supported by PC and Mac versions but they are unreliable and in many cases will cause PowerPoint to crash

Finally, to get around the Auto_Open limitation of only firing within an add-in (as opposed to a presentation), you can use this article to solve that issue (again, only for PC versions of PowerPoint supporting the ribbon):


Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.