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

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Make your VBA code in PowerPoint respond to events

PowerPoint 97 doesn't support events, so it can't automatically run macros when a presentation opens, at print time, etc. PowerPoint 2000 and later 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 code sample (referred to below) on the same page. Search for "Event Handler Demo in PowerPoint 2000+".

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 explains 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:

SlideShow events

Window events

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

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:

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. The Object Variable PPTEvent will 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 wish 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.

Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2015 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 your VBA code in PowerPoint respond to events
http://www.pptfaq.com/FAQ00004_Make_your_VBA_code_in_PowerPoint_respond_to_events.htm
Last update 07 September, 2011
Created: