PowerPoint Events

  • Thread starter Karl E. Peterson
  • Start date
K

Karl E. Peterson

Hi --

Is this the best group for posting questions about VBA in PowerPoint?
I couldn't find any that seemed more specific to that product.

Anyway, I'm wondering about doing a few things in PPT, and haven't
worked much in it before. We need to put up a "speaker timer", similar
to those used in political debates, to allow each speaker at a meeting
a visible indication of how much time they have remaining. I'm not
sure whether to do this directly with PPT objects, or to write an OCX
in VB6.

I think in either case, I'll need to know when that particular slide is
activated, so that I may suitably initialize things. What's the best
way to do that?

Thanks... Karl
 
S

Steve Rindsberg

Karl E. Peterson said:
Hi --

Is this the best group for posting questions about VBA in PowerPoint?
I couldn't find any that seemed more specific to that product.

Here or Public.PowerPoint, Karl.
Anyway, I'm wondering about doing a few things in PPT, and haven't
worked much in it before. We need to put up a "speaker timer", similar
to those used in political debates, to allow each speaker at a meeting
a visible indication of how much time they have remaining. I'm not
sure whether to do this directly with PPT objects, or to write an OCX
in VB6.

I think in either case, I'll need to know when that particular slide is
activated, so that I may suitably initialize things. What's the best
way to do that?

What version(s) of PPT will need to support?

Not sure when this event was introduced but it's there in 2003 and up, and
it'd be where you want to hang this, I think:

Event SlideShowNextSlide(Wn As SlideShowWindow)

Member of PowerPoint.Application


Your event handler would probably want to do something with:

With Wn
' current slide
.View.Slide.SlideIndex
' number of slides in the presentation
.Presentation.Slides.Count
End With

SlideIndex gives you the ordinal position of the slide in the slide show.
(Don't use SlideNumber ... it gives you the number that appears on the
slide, which can vary depending on where the user has chosen to start
numbering)

Count gives you the number of slides in the presentation.

Caveats:

Some slides might be hidden, which could throw off any "You're on Slide N
of Y" notifications.

If you change text on a slide that's currently visible, you may need to
use .GotoSlide (.Slide.SlideIndex) to force a refresh.
 
K

Karl E. Peterson

Steve said:
Here or Public.PowerPoint, Karl.

Hi Steve! I did wander through there, and saw a few VBA posts, but
most seemed more geared towards the main app. Finding you here means
I'm not in bad company, though. :)
What version(s) of PPT will need to support?

Sorry, should've said. 2003, most likely. For sure, at first.
Not sure when this event was introduced but it's there in 2003 and up, and
it'd be where you want to hang this, I think:

Event SlideShowNextSlide(Wn As SlideShowWindow)

Member of PowerPoint.Application


Your event handler would probably want to do something with:

With Wn
' current slide
.View.Slide.SlideIndex
' number of slides in the presentation
.Presentation.Slides.Count
End With

I did find one event handling class, while googling around, and it
seemed geared towards the entire application. Sounds like this is the
same idea. I'm just not that familiar with that model, and dealing
with its lifetime issues.

Odds are, this presentation will be a 1-slide standalone, that will be
called by clicking somewhere in another presentation. Is there a best
way to rig up the event handling so it's only active during this single
presentation?
SlideIndex gives you the ordinal position of the slide in the slide show.
(Don't use SlideNumber ... it gives you the number that appears on the
slide, which can vary depending on where the user has chosen to start
numbering)

Good tip, thanks!
Count gives you the number of slides in the presentation.

Caveats:

Some slides might be hidden, which could throw off any "You're on Slide N
of Y" notifications.

Okay said:
If you change text on a slide that's currently visible, you may need to
use .GotoSlide (.Slide.SlideIndex) to force a refresh.

See, I'm not even sure of the best way to update an element on the
slide. Currently, I'm doing something like this:

With shpTimer.TextFrame.TextRange
If NewText <> .Text Then
.Text = NewText
End If
If NewColor <> .Font.Color Then
.Font.Color = NewColor
End If
End With

But that just feels "heavy" for some reason. It's definitely a
learning experience!
 
S

Steve Rindsberg

Hi Steve! I did wander through there, and saw a few VBA posts, but
most seemed more geared towards the main app. Finding you here means
I'm not in bad company, though. :)

Some might reach the opposite conclusion said:
Sorry, should've said. 2003, most likely. For sure, at first.

OK. No problem there. Less bugful than 2007 too.
I did find one event handling class, while googling around, and it
seemed geared towards the entire application. Sounds like this is the
same idea. I'm just not that familiar with that model, and dealing
with its lifetime issues.

Meant to fling this atcha:

Make your VBA code in PowerPoint respond to events
http://www.pptfaq.com/FAQ00004.htm

It should help.
Odds are, this presentation will be a 1-slide standalone, that will be
called by clicking somewhere in another presentation. Is there a best
way to rig up the event handling so it's only active during this single
presentation?

You'll probably want to include logic in the event handler to let it look for
some known property of your presentation and only do its stuff if it finds that
... a presentation-level tag, for example.

If ActivePresentation.Tags("SimonSays") = "GO" Then
' do yer stuff
Else
Exit Sub
End If


Good tip, thanks!




See, I'm not even sure of the best way to update an element on the
slide. Currently, I'm doing something like this:

With shpTimer.TextFrame.TextRange
If NewText <> .Text Then
.Text = NewText
End If
If NewColor <> .Font.Color Then
.Font.Color = NewColor
End If
End With

But that just feels "heavy" for some reason. It's definitely a
learning experience!

Looks about right to me though, Karl.
 
K

Karl E. Peterson

Steve said:
Some might reach the opposite conclusion, given the same facts. <g>

Birds of a feather... said:
OK. No problem there. Less bugful than 2007 too.

Nice adjective. Must re-use...
Meant to fling this atcha:

Make your VBA code in PowerPoint respond to events
http://www.pptfaq.com/FAQ00004.htm

It should help.

Yeah, that's the one I was playing with, alright. I guess I didn't
plumb it deep enough. At the time, I was more preoccupied with just
getting the main functionality in place, to see how folks would like
it.
You'll probably want to include logic in the event handler to let it look for
some known property of your presentation and only do its stuff if it finds
that .. a presentation-level tag, for example.

If ActivePresentation.Tags("SimonSays") = "GO" Then
' do yer stuff
Else
Exit Sub
End If

So these things are, by nature, application focused, and really can't
be restricted to just a single presentation (other than by rules like
this)?
Looks about right to me though, Karl.

Huh. Okay. I was thinking there may be some "lighter" way to
manipulate a text-bearing object. To speak VBish, something that only
affected the "runtime" behavior and not the "designtime"
characteristics as well. I guess I need to adapt to the different
metaphor!

Thanks again... Karl
 
S

Steve Rindsberg

[snip snip]
Yeah, that's the one I was playing with, alright. I guess I didn't
plumb it deep enough. At the time, I was more preoccupied with just
getting the main functionality in place, to see how folks would like
it.

I've managed to do this kind of thing w/o an add-in by letting an action setting
trigger a macro that wakes up the event handler and jumps to the appropriate
slide. It's a bit less reliable than an add-in but allows you to run everything
from within a single presentation file rather than requiring an add-in to load.
 
K

Karl E. Peterson

Steve said:
[snip snip]
Yeah, that's the one I was playing with, alright. I guess I didn't
plumb it deep enough. At the time, I was more preoccupied with just
getting the main functionality in place, to see how folks would like
it.

I've managed to do this kind of thing w/o an add-in by letting an action
setting trigger a macro that wakes up the event handler and jumps to the
appropriate slide. It's a bit less reliable than an add-in but allows you
to run everything from within a single presentation file rather than
requiring an add-in to load.

Interesting! I didn't know an action could trigger a macro. (By
"action", I presume you mean something like text flying into the slide,
or such, right?) Yeah, that could serve perfectly for a situation like
this. I'll have to see how to set that sort of hook. Thanks!
 
S

Steve Rindsberg

Steve said:
[snip snip]
Meant to fling this atcha:

Make your VBA code in PowerPoint respond to events
http://www.pptfaq.com/FAQ00004.htm

It should help.

Yeah, that's the one I was playing with, alright. I guess I didn't
plumb it deep enough. At the time, I was more preoccupied with just
getting the main functionality in place, to see how folks would like
it.

Odds are, this presentation will be a 1-slide standalone, that will be
called by clicking somewhere in another presentation. Is there a best
way to rig up the event handling so it's only active during this single
presentation?

I've managed to do this kind of thing w/o an add-in by letting an action
setting trigger a macro that wakes up the event handler and jumps to the
appropriate slide. It's a bit less reliable than an add-in but allows you
to run everything from within a single presentation file rather than
requiring an add-in to load.

Interesting! I didn't know an action could trigger a macro. (By
"action", I presume you mean something like text flying into the slide,
or such, right?) Yeah, that could serve perfectly for a situation like
this. I'll have to see how to set that sort of hook. Thanks!

Close ... if you rightclick on practically anything in PPT you can choose Action
Settings from the popup menu. If there are any macros in the PPT file, you can
choose Run Macro and pick the one you want to run.

Now we get sneaky ... you can also run a macro in response to a mouseover. So
imagine an 99% transparent rectangle over the whole slide (ie, invisible) ...
user waggles the mousie anywhere on the slide and your macro gets triggered w/o
them having to do anything deliberately.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top