PDA

View Full Version : How do I get to the list of procedures that are event-linked on the PowerPoint VBA ID



braddenn
11-25-2008, 01:42 PM
I’m adding an App_PresentationClose event handler to a 2007 PowerPoint set of slide modules. I have followed the Microsoft “How to: Use Events with the Application Object “ notes and have set up an object variable of type Application in an Event Class Module. Also, in Module1 I have an InitializeApp() function that I successfully call from another slide module. But the event does not trigger the Private Sub App_PresentationClose(ByVal pres As Presentation) that I wrote. I suspect, based on some VB6 experience, that I have not associated the App_PresentationClose Sub with the event.

The Microsoft MSDN note says,
“After the new object is declared with events, it appears in the Object list in the class module, and you can write event procedures for the new object. (When you select the new object in the Object list, the valid events for that object are listed in the Procedure list.) Select an event from the Procedure list; an empty procedure is added to the class module.”

I can’t find an Object list or Procedure list. I am using the “Developer” tab in PowerPoint to get to the Microsoft Visual Basic development window which is a rather limited IDE. It has an Object Browser which shows classes and class members – but it does not have an Object list or Procedure list. I expect to see a list of procedures that are associated with the “WithEvents” part of type Application. Then I could find the “App_PresentationClose” procedure, double-click on that and have an empty event-linked procedure inserted into my code space. Then I fill in the details. But I cannot find that procedure anywhere.
How do I get to the list of procedures that are event-linked on the PowerPoint VBA IDE?

braddenn
11-25-2008, 05:52 PM
Well, I learned some things.
1. The App_PresentationClose event does not occur when the presentation is closed via 'esc' or for other reasons. It occurs when I close Powerpoint. So it does not occur when run by the viewer, it occurs when the developer closes powerpoint. Not very useful.
2. I cannot get a call to another powerpoint.ppsm show to happen. The code always hangs at that call. So I cannot use an Application.Run call to InitializeApp in another slide show. I tried this with the other show running and also with it not running.

I'm trying to log the time when a student exits the training module. It's easy when the student clicks on the Next or Home buttons I added to the last slide. But if the student does an 'esc' or logs out I have no record.

Paul_Hossler
11-25-2008, 08:32 PM
You may already know this, but in the IDE when you create the Class module and put this is


Public WithEvents App As Application


there are 2 long dropdown boxes (General) and (Declarations)

In (General) you can select App or Class. If you select App, youi can see all the events that the Application can respond to, including App_SlideShowEnd which I "think" is the one that you want. The event handler looks like this:


Option Explicit
Public WithEvents App As Application

Private Sub App_SlideShowEnd(ByVal Pres As Presentation)
MsgBox "Ending"
End Sub


However, you still need to Set the Application to your class with your even handlers

Microsoft's How-To shows this bit of code, but the Sub still has to be run, and people usually tell you that you need to have an add-in to do the PP equivalent of an "Auto_Run"

Dim X As New EventClassModule
Sub InitializeApp()
Set X.App = Application
End Sub



I've found that I can create a bare bones CustomUI using the CustomUI editor and have the OnRibbonLoad sub do it instead of running the init sub manually or having to make sure that the add in is available.

'<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad" >
'<ribbon>
'</ribbon>
'</customUI>

So after I add the CustomUI to the PPTM file, a standard module with this


Option Explicit
Dim X As New EventClassModule

'Callback for customUI.onLoad
Sub OnRibbonLoad(ribbon As IRibbonUI)
Set X.App = Application
End Sub


seems to initialize the New instance of the class just fine ( .... so far)

Paul

braddenn
11-26-2008, 11:32 AM
Thanks Paul,
That worked as far as using App_SlideShowEnd instead of App_PresentationClose. Yes, I did not notice and pull down the General and Declarations dropdowns. I've ignored those for years.

Next - the Initialize. I am running a series of slide shows. A ends, user hits Next button and A starts B with Presentation.Open. See below. That part works well.

' start the next module
Presentations.Open (NextModulePath)
MsgBox "call 102_environment"
Application.Run "100_Foundations\102_environment.ppsm!Module1.InitializeApp"
' exit this show
MsgBox "exit 101"
SlideShowWindows(2).View.Exit

However, the Application.Run does not get to module 102. It hangs which usually indicates something is wrong. Any ideas on why it doesn't get to 102 which is running and I've checked my path with CurDir().

If I can't get this to work I'll have to investigate using the callback - haven't researched CustomUI yet but the callback idea seems solid.

braddenn
11-26-2008, 12:41 PM
OK!! Got it to work. It was a curdir() issue. Now I run show A, it Opens B, calls InitializeApp in B, and exits. The ShowEnd event is happening - although it seems to also happen at show start. If so I can handle that.
Thanks for the help.

Paul_Hossler
11-26-2008, 04:32 PM
Life is good :-)