views:

38

answers:

1

Hi, 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.

+2  A: 

The macro in the presentation that was created has no way to run, as the auto_open macro only works with addins. Based on the way you're doing it, you'd have to reload the ribbon to kick the event in your new presentation you want to run.

Mahin
I found that I can create an Add-In and put code in that. But at the point that the code from the add-in is run, the code from the template can't run. I mean, I can reach the code and see if it exists, but I can't run it. The solution so far is to run all of the code from the add-in itself. And just do a check to see if the template name equals something I want. To make sure the code is only run in the templates I want and not globally.
Kenny Bones
You mean even if you use `Application.Run` you can't run the code? Like here: http://www.pptfaq.com/FAQ00403.htm
Mahin