Supercharge your PowerPoint productivity with

Supercharge your PPT Productivity with PPTools - Click here to learn more.

Tell me about PPTools

Make PPT respond to events


PPTools
Shape Styles brings the power of styles to PowerPoint. Apply complex formatting with a single click
Merge Excel, CSV or tab-delimited data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more
FixLinks prevents broken links when you distribute PowerPoint presentations
Optimizer saves disk space and bandwidth, shrinks your PowerPoint presentations to the right size for email, screenshow or printing
PPT2HTML gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements
Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF
Image Export converts PowerPoint slides to JPG, PNG, GIF, WMF and more

PowerPoint 97 doesn't support events, so it can't automatically run macros when a presentation opens, at print time, etc. PowerPoint 2000 does support events, so there are some interesting possibilities. PowerPoint MVP Shyam Pillai has graciously provided this tutorial.

See Shyam's download section for his AutoEvents add-in for PowerPoint - it does all the tricky stuff for you, and it's free. I'm not giving you the direct link to the file because there's a ton of other useful stuff on the downloads page. You owe it to yourself to have a look!

There's also an Event Handler demo (referred to below) on the same page

Chirag Dalal has also written an excellent event capture add-in and has posted this very useful PowerPoint Event Table that lists events, versions of PPT that support them and mentions the order in which the events fire.

Events in PowerPoint 2000 are limited to Application level as compared to those available across Excel and Word. They can be essentially grouped into 3 categories:

Presentation events:

  • NewPresentation
  • PresentationOpen
  • PresentationNewSlide
  • PresentationSave
  • PresentationPrint
  • PresentationClose

SlideShow events

  • SlideShowBegin
  • SlideShowEnd
  • SlideShowNextBuild
  • SlideShowNextSlide

Window events

  • WindowActivate
  • WindowBeforeDoubleClick
  • WindowBeforeRightClick
  • WindowDeactivate
  • WindowSelectionChange

Later versions of PPT have introduced a few new events. To see the available events in the version you're using:

  • Press Alt+F11 to open the VBA editor (the IDE).
  • In the IDE, press F2 to open the object browser.
  • Scroll down to Application in the Classes list and click it.
  • In the Members window on the right, look for lightning bolt icons. Those are the events supported by your version of PPT.

How do you create a event handler?
An object that raises events is called an event source. To handle the events raised by an event source, you can declare a variable of the object's class using the WithEvents keyword. "WithEvents" keyword is used to create an object variable that responds to events that are activated by an ActiveX
object.

Things to be noted about WithEvents:

  • WithEvents keyword is valid only in a class module
  • WithEvents variable cannot be a generic object variable, the class name has to be used.
  • You cannot declare a WithEvents variable As New.
  • You cannot create arrays of WithEvents variables.

Steps to create the handler:

  1. Open a new presentation.
  2. Launch VBE (Alt+F11). Insert a new class into the project
  3. Type the line given below:

  4. Public WithEvents PPTEvent As Application
    The WithEvents keyword specifies that the variable PPTEvent will be used to handle an object's (application) events.
  5. Now click on the Object combo box. Object Variable PPTEvent would be listed there. Select PPTEvent. In the adjoining Procedure combo box select from one of the choices of events listed and add appropriate code to the events that you desire to handle.
  6. Now insert a new module sheet. cEventClass is the name of the class I created. Hence add the following line:

  7. Dim cPPTObject As New cEventClass
    This is done because we need to instantiate an object of the cEventClass and then set the reference of the object variable PPTEvent to the powerpoint application.. The reference is set in the TrapEvents routine by the line given below:
    Set cPPTObject.PPTEvent = Application
    In the EventHandler Demo, look up the routine TrapEvents for this statement. Execute it. This will activate the eventhandler
  8. To terminate the eventhandler set the refernce of the object variable to Nothing (just like any other object variable) like this:

  9. Set cPPTObject.PPTEvent = Nothing
    In the file this statement will be encountered in the ReleaseEvent routine.

Things to be noted...

  • An Event handler cannot be set automatically. To set an event handler when PowerPoint starts up you still need to rely on the Auto_Open macro of an add-in to instantiate the event handler.
  • An event handler is disabled as soon as the presentation/add-in in which it resides is closed/unloaded.

Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2008 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese



Supercharge your PPT Productivity with PPTools


content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Make PPT respond to events
http://www.pptfaq.com/FAQ00004.htm
Last update 18 August, 2008