so I've found that PowerPoint 2007 does indeed support event handlers on the Application level. For example Application.NewPresentation
or even Application.AfterNewPresentation
It's described here http://msdn.microsoft.com/en-us/library/ff745073.aspx
But the real question is, how do I use these? Where do I use them? To tell you my scenario, what I want is to insert dynamic text into a few textboxes. I have the macro code to do this and it's working exactly as I want it to. But I need the macro to fire once a new presentation is created from a potm template. And only on that event. Just like it does in Word 2007.
Where do I start? I tried to just create a sub looking like this and saving it as a potm file and open a new presentation based on that template. And nothing happened.
Private Sub App_NewPresentation(ByVal Pres As Presentation)
MsgBox "Running!"
End Sub
Edit: It is possible to open any Office 2007 file with an XML editor. I use the Custom UI Editor For Microsoft Office and in that I add a Office 2007 Custom UI.XML part following the guide presented here: http://www.pptalchemy.co.uk/PowerPoint_Auto_Open_Code.html
But I run into problems when PowerPoint creates a new presentation based on that template. Opening the template in itself works just fine. The event handler is there and the code is run beautifully. But a new presentation based on it? No way, the handler is there as well. But it says it cannot find the macro. Even though the macro is in the new presentation as well since I can open Visual Basic Editor and find the macro and then run it. It's just the autopart that doesn't seem to be working like it should.
The only way to create an auto macro in PowerPoint VBA is to have your file as an Add-in (.ppa or .ppam - not .pptx/.pptm/.potm/etc). And the way to create it is:
Option XXX
), put
Public WithEvents App As
Application
and then put your
routine above below that.Create a module of any name and put:
Dim X As New Class1
Sub AutoOpen()
Set X.App = Application
''# Code to create new presentation
End Sub
Again, this will not work from your requirement of .potm. Another way that you can consider has been depreciated, but it still works, which is to create a Wizard file.