PowerPoint 97 and events

  • Thread starter Thread starter Gervase Markham
  • Start date Start date
G

Gervase Markham

No, I'm not asking for the impossible - I know PowerPoint 97 doesn't
support events :-). What I'm looking for is a way of making an add-in
that supports events in 2000 while still working (without the events) in 97.

Having followed Shyam's excellent tutorial:
http://www.rdpslides.com/pptfaq/FAQ00004.htm
I now have a class module called UIState, which begins:

Public WithEvents PPTEvent As Application

In Auto_Open(), I do:
Dim UIStateObserver As New UIState
Set UIStateObserver.PPTEvent = Application
....and so on.

However, the PPT97 Visual Basic compiler doesn't like the WithEvents
keyword there - I get:
"Object does not source automation events".

Fair enough, I think - I need to have one variable without WithEvents
for 97, and one with it for 2000. Obvious try:

If Application.Version > 8 Then
Public WithEvents PPTEvent as Application
Else
Public PPTEvent As Application
End If

Of course, this doesn't work; the If statement is flagged with:
"Invalid outside procedure"

So, the question:

Is there any way of inserting a code fork such that PowerPoint 2000 and
above see the WithEvents version, and 97 the plain version? Or some
other method or way of arranging the code to get them to peacefully coexist?

If not, my only options are
a) two downloads, or
b) abandon the events.
Both these options suck. :-(

Many thanks,

Gerv
 
Steve said:
In some cases you can declare things As Object rather than As
<ThingThatPPT97Doesn'tSupport> but that won't help in this case, I don't
think.
I had a go at that; no luck.

If I do:
Public WithEvents PPTEvent As Object
in PowerPoint 97, I get an alert box:
"Compile error. Expected: identifier."
and the word "Object" is highlighted.
However, if you have two code paths:

If Is97 Then
' Blah97
Else
' Blah2000
End if

and compile it under 2000, it should run in 97.

Yes, I've used that technique in other places. But it won't work here
because you can't have "code paths" outside subroutines or functions,
and what I'm doing here is declaring a class variable WithEvents.

Can any variable types be declared WithEvents in PPT97? Can you ReDim
(as it were) a variable to a different type while you are running?

Gerv
 
In some cases you can declare things As Object rather than As
I had a go at that; no luck.

Didn't expect so, as in "won't help in this case, I don't think" above. ;-)
 
In some cases you can declare things As Object rather than As
I had a go at that; no luck.

I didn't expect it would.
Yes, I've used that technique in other places. But it won't work here
because you can't have "code paths" outside subroutines or functions,
and what I'm doing here is declaring a class variable WithEvents.

Ah, I see what you mean.
Hm. I don't have 97 available at the moment, but what if you were to do all
the necessary version-specific hocuspocus in two external add-ins, one for
each version of PPT? Couldn't you then demand-load the appropriate one
depending on which version your main routine found itself living within?
 
Steve said:
Demand-load = loading an addin under program control instead of having the
user explicitly load/unload it.
Something along these lines:

If PPT97 then
AddIns.Add(FullPathToPPAFiles & "PPT97Extras.PPA").Loaded = True
Else
AddIns.Add(FullPathToPPAFiles & "PPTNormalExtras.PPA").Loaded = True
End If

Ah. Sounds good. I'll go and look into that. The big question would be
whether the two "halves" - the root and the extras - can communicate
efficiently. One half needs to declare variables for the other half to
use...

The "main part" could be a stub; but then users would be downloading my
add-in twice (and I'd have to maintain two copies), which would suck.
The main part really needs to contain all the common code.

Gerv
 
If PPT97 then
Ah. Sounds good. I'll go and look into that. The big question would be
whether the two "halves" - the root and the extras - can communicate
efficiently. One half needs to declare variables for the other half to
use...

This might help, and I think there are some more ideas on
http://www.mvps.org/skp (Shyam's site)
Call a macro in another presentation and pass it parameters
http://www.rdpslides.com/pptfaq/FAQ00403.htm
The "main part" could be a stub; but then users would be downloading my
add-in twice (and I'd have to maintain two copies), which would suck.
The main part really needs to contain all the common code.

I don't think that will be too big a problem, as long as you've no problems
with using globals.
Globals declared in the main addin should be accessible to the called or
"demand-loaded" one.
 
Back
Top