|PowerPoint tips, hints and tutorials that will change your presentations for ever!|
Run Code When PowerPoint Opens
In most office programs it is possible to run code when the document opens. In Excel for example you have a Workbook_Open Event. Not so in PowerPoint.
Most information will tell you either that this cannot be done OR to use a Sub named Auto_Open.
Auto_Open will ONLY work from a ppa or ppam Add In which restricts its use severely for the normal user. However in xml based versions (from 2007) it is possible to run code when the presentation loads, the equivalent of the Workbook_Open event.
First create the sub you want to auto open, in our example it must be named OnLoadCode but it should be obvious how to change this if you read on.
Probably your code will do a little more than this!
Now save as a .pptm macro enabled file.
The easiest way to add XML is to use the free CustomUIEditor which you can download here:
Once installed start the Custom UIEditor and use it to open the saved pptm file. Now choose Insert>Office 2007Custom UI Part (this will also work in 2010)
Now paste in this XML:
This simply means that onLoad the code in the sub OnLoadCode will run. Be careful with upper and lower case - it matters! The code will only run if macro security is set low enough.
Note that onLoad refers to the RIBBON onLoad event not the presentation load event. If there is no ribbon the event will not fire. Opening a .ppsm file direct to show mode will NOT fire the event because the ribbon does not load.
File Save and you are done.
Test it out!
Free Microsoft PowerPoint Advice, help and tutorials, Template Links