forward and backward slide transitions .. programming different so

G

gvm

I have a certain sound play each time the ppt slide show transitions forwards
from one slide to the following one. The same sound plays when I transition
in reverse, ie from one slide to the previous slide. Using standard
functions, is it possible to set different sounds when transitioning forward
and in reverse?

If not, can a macro be written that runs each time there is a slide
transition, detects whether the transition is forward or backward, and
depending on the direction plays either one of two sounds?
TIA .... Greg
 
S

Steve Rindsberg

I have a certain sound play each time the ppt slide show transitions forwards
from one slide to the following one. The same sound plays when I transition
in reverse, ie from one slide to the previous slide. Using standard
functions, is it possible to set different sounds when transitioning forward
and in reverse?

No, afraid not.
If not, can a macro be written that runs each time there is a slide
transition, detects whether the transition is forward or backward, and
depending on the direction plays either one of two sounds?

Probably so. You'd need to implement an event handler in an add-in:

Make PPT respond to events
http://www.pptfaq.com/FAQ00004.htm

It could trap slide changes and by storing the previous slide's Index in a
global or static variable, compare that with the current slide to work out if
you're moving forward or backward.

I'm not sure exactly when the event fires though ... on or after slide change.
That might make a difference.
 
G

gvm

Steve, thanks but I need more help to get started. Can you assist further
please? TIA ... Greg
 
S

Steve Rindsberg

Steve, thanks but I need more help to get started. Can you assist further
please? TIA ... Greg

If I can, sure, but if you've never done any VBA/VB programming before, this isn't
really a starter project.
 
G

gvm

I understand your point Steve; my VBA experience is in Excel and so its use
with ppt is what's new for me ... Greg
 
S

Steve Rindsberg

I understand your point Steve; my VBA experience is in Excel and so its use
with ppt is what's new for me ... Greg

That's bigtime different from no experience in Office/VBA at all. ;-)

You'll want to read the tutorial at the link below. It explains how to set up an event
handler. For most purposes, you'll want to save this and the associated code as an
Add-in (PPA).

Once the event handler is active, it'll run code of your choosing (the code in the
individual event routines or code called from there) when certain events happen.

Since there's only a SlideShowNextSlide event, you'll need to see if it fires even when
you move to slides other than the one following the current one. If not, it may not be
possible to do what you're after, at least not the way I'm thinking of.

At the end of the routine you fire with this event, you'd update a global
LastSlideViewed variable to the current .SlideIndex. Next time into the routine you
compare the current slide number with LastSlideViewed. If

If SlideShowWindows(1).View.Slide.SlideIndex > LastSlideViewed Then
' we moved forward
Else
' we moved backward
End If
 
G

gvm

Excellent, thanks Steve ... Greg

Steve Rindsberg said:
That's bigtime different from no experience in Office/VBA at all. ;-)

You'll want to read the tutorial at the link below. It explains how to set up an event
handler. For most purposes, you'll want to save this and the associated code as an
Add-in (PPA).

Once the event handler is active, it'll run code of your choosing (the code in the
individual event routines or code called from there) when certain events happen.

Since there's only a SlideShowNextSlide event, you'll need to see if it fires even when
you move to slides other than the one following the current one. If not, it may not be
possible to do what you're after, at least not the way I'm thinking of.

At the end of the routine you fire with this event, you'd update a global
LastSlideViewed variable to the current .SlideIndex. Next time into the routine you
compare the current slide number with LastSlideViewed. If

If SlideShowWindows(1).View.Slide.SlideIndex > LastSlideViewed Then
' we moved forward
Else
' we moved backward
End If



--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
G

gvm

Steve,
I have based my macro on Shyam Pillai's sub that reports the index number in
a message box after each slide transition. Use of the sub shows that the
variable "index" reports the correct slide number transitioning both forwards
and backwards. Since Nextslide runs before moving to the next slide and I
read that "SlideIndex" is the index of the next slide, I thought the test for
whether transition is forward or back is simply a comparison of Shyam's
"index" and "SlideIndex".

So what follows is my adaptation of Shyam's macro. I expect there are a
number of problems in it, but the first is that the sub loops on the first
slide, ie the message box pos up repeatedly and it is necessary to terminate
ppt to get out of the loop. I would appreciate your help, TIA .. Greg

Sub Auto_NextSlide(Index As Long)
Dim CurrentSlide As Long
CurrentSlide = Index
MsgBox "Slide No:" & Index
If ActivePresentation.SlideShowWindow.View.Slide.SlideIndex >
CurrentSlide Then
' we moved forward
ActivePresentation.Slides(1).SlideShowTransition.SoundEffect _
.ImportFromFile "c:\program files\microsoft office\media\laser.wav"
Else
' we moved backward
ActivePresentation.Slides(1).SlideShowTransition.SoundEffect _
.ImportFromFile "c:\program files\microsoft office\media\type.wav"
End If
End Sub
 
S

Steve Rindsberg

Give this a try instead:

First, you need to add this to the event class if it's not already there:

Private Sub PPTEvent_SlideShowNextSlide(ByVal wn As SlideShowWindow)
Call Auto_NextSlide(wn)
End Sub

Note that the parameter passed to the event is the slide show window, not the slide
index; in your code module, this:

Sub Auto_NextSlide(wn As SlideShowWindow)
' Note again that the slide show window is the parameter,
' not slide index

' declare this as static so its value
' is retained between invocations of the sub
Static LastSlide As Long

Dim CurrentSlide As Long

CurrentSlide = wn.View.Slide.SlideIndex

MsgBox "Slide No: " & CurrentSlide

If LastSlide = 0 Then
' we just started the show
' add special case code here or ignore
'
' we'll ignore:
LastSlide = CurrentSlide
Exit Sub
End If

If CurrentSlide > LastSlide Then
' we moved forward
ActivePresentation.Slides(1).SlideShowTransition.SoundEffect _
.ImportFromFile "c:\program files\microsoft office\media\laser.wav"
Else
' we moved backward
ActivePresentation.Slides(1).SlideShowTransition.SoundEffect _
.ImportFromFile "c:\program files\microsoft office\media\type.wav"
End If

LastSlide = CurrentSlide

End Sub
 
G

gvm

Thanks Steve.
I updated the macro code you provided me in
VBAProject(test.ppt)/Modules/Module 1 and created and pasted the Private Sub
PPTEvent subroutine in VBAProject(test.ppt)/Class Modules/Class 1.

AutoEvents is enabled within ppt but the event and/or macro is not firing.
Have I interpreted your instructions correctly?

I noticed that if I select Tools/Macro/Macros from test.ppt, no macros are
listed as being present in test.ppt. Is this expected, or is it an indication
of why I have a problem?

Thanks again Steve, I appreciate your patience with me ... Greg
 
S

Steve Rindsberg

Thanks Steve.
I updated the macro code you provided me in
VBAProject(test.ppt)/Modules/Module 1 and created and pasted the Private Sub
PPTEvent subroutine in VBAProject(test.ppt)/Class Modules/Class 1.

AutoEvents is enabled within ppt but the event and/or macro is not firing.
Have I interpreted your instructions correctly?

Possibly, but remember that within a PPT, every time you edit the macro or get an error
message, it's likely going to disable event trapping, so you have to re-set the event
trap.
I noticed that if I select Tools/Macro/Macros from test.ppt, no macros are
listed as being present in test.ppt. Is this expected, or is it an indication
of why I have a problem?

Not sure ... is test.ppt the file where your macros are stored?
 
G

gvm

Steve,
re your question "is test.ppt the file where your macros are stored?", the
answer is I think so; - the macro is visible when I view the source code in
VBAProject(test.ppt)/Modules/Module 1.

Re your point about having to reset the event handler: I disabled and
re-enabled Auto Events inside ppt. Is that the way to reset the event trap?
Doing so appears to have failed to make any difference - tne event handler /
macro still doesn't fire.

kind regards ... Greg
 
S

Steve Rindsberg

I missed something in your earlier post ... my bad

The line:

Dim cPPTObject As New cEventClass

assumes that you have a class named cEventClass

Try renaming your Class1 to that.
 
G

gvm

Thanks again Steve. re your advice "The line:
Dim cPPTObject As New cEventClass
assumes that you have a class named cEventClass
Try renaming your Class1 to that."

two things:
(1) How do I rename the Class1 module please? Obviously it is not as easy as
right clicking and selecting Rename on the VBAProject(test.ppt)/Class
Modules/Class 1 icon.
(2) Perhaps my code is incomplete because neither the statement "Dim
cPPTObject As New cEventClass" nor cPPTObject is apparent in my code. I have
pasted my code from both modules below for your inspection. Regards ... Greg
Stored in: VBAProject(test.ppt)/Class Modules/Class 1....
Private Sub Class_Initialize()
End Sub
Private Sub PPTEvent_SlideShowNextSlide(ByVal wn As SlideShowWindow)
Call Auto_NextSlide(wn)
End Sub

And stored in VBAProject(test.ppt)/Modules/Module 1
Sub Auto_NextSlide(wn As SlideShowWindow)
' Note again that the slide show window is the parameter, not slide index
' declare this as static so its value is retained between invocations of
the sub
Static LastSlide As Long
Dim CurrentSlide As Long
CurrentSlide = wn.View.Slide.SlideIndex
MsgBox "Slide No: " & CurrentSlide

If LastSlide = 0 Then
' we just started the show
' add special case code here or ignore
'
' we'll ignore:
LastSlide = CurrentSlide
Exit Sub
End If

If CurrentSlide > LastSlide Then
' we moved forward
ActivePresentation.Slides(1).SlideShowTransition.SoundEffect _
.ImportFromFile "c:\program files\microsoft office\media\laser.wav"
Else
' we moved backward
ActivePresentation.Slides(1).SlideShowTransition.SoundEffect _
.ImportFromFile "c:\program files\microsoft office\media\type.wav"
End If

LastSlide = CurrentSlide
End Sub


-------- end of code -----------
 
S

Steve Rindsberg

Thanks again Steve. re your advice "The line:
Dim cPPTObject As New cEventClass
assumes that you have a class named cEventClass
Try renaming your Class1 to that."

two things:
(1) How do I rename the Class1 module please? Obviously it is not as easy as
right clicking and selecting Rename on the VBAProject(test.ppt)/Class
Modules/Class 1 icon.

You need to have the Properties window open. Then when you click on your class module, you'll
see its name next to (Name). Click in the name to the right of that to edit/change it.
(2) Perhaps my code is incomplete because neither the statement "Dim
cPPTObject As New cEventClass" nor cPPTObject is apparent in my code.

That'll keep it from working all right. Check Shyam's Event Handler demo on this page:

http://skp.mvps.org/download.htm

I'd start with that, verify that it's working, then comment out what you don't need and add your
own code back into it.

I have
 
G

gvm

Dear Steve,
the job is nearly done, thanks so much for your help. The problem now is the
commands intended to create the soundeffects are wrong. Can you suggest the
correct way to set and play the sounds please?

Also, does the event handler have to be started and ended manually using the
button on Shyam's slide? Or can this manual procedure be substituted by
simply enabling and disabling the event handler on the tools/auto events drop
down menu?

This is so exciting for me. I have confirmed the only remaining problem is
the playing of the sound effect because I have watched the macro step to the
appropriate sound effect command depending on whether the transition is
forward or reverse. Hooray!

TIA ... Greg
 
S

Steve Rindsberg

Dear Steve,
the job is nearly done, thanks so much for your help. The problem now is the
commands intended to create the soundeffects are wrong. Can you suggest the
correct way to set and play the sounds please?

Too sleepy to answer that one coherently ... hang in there. ;-)
Also, does the event handler have to be started and ended manually using the
button on Shyam's slide? Or can this manual procedure be substituted by
simply enabling and disabling the event handler on the tools/auto events drop
down menu?

Generally, the event handler would be initialized in the Auto_Open subroutine in an add0-in

Tools/AutoEvents dropdown menu ..? Where's THAT bad boy? ;-)
 
G

gvm

Ha ha, I use three PCs, two of them are still ppt 2003 and one is ppt 2007.
I'll check the alternative to tools/auto events when I'm back at work! cheers
.... Greg
 
G

gvm

Steve,
I have had a go at coding the setting and playing of soundeffects but I
can't test it because for some reason the events are no longer being trapped.
I've checked Shyam's buttons are linked to the trap macros, that the add-in
is enabled, that the security settings permit macros and trust VBA projects.
What else might the problem be?

Here's my code for sounding appropriate sound effect. It is based on stuff I
found on the net. Does it look OK?

Dim oshpf As Shape
Dim oshpr As Shape
Dim oeff As Effect

Inside the if currentslide>last slide if statement:
If we moved forward…
Set oshpf = ActivePresentation.Slides(1) _
..Shapes.AddMediaObject(laser.wav)
Set oeff = ActivePresentation.Slides(1).TimeLine _
..MainSequence.AddEffect(oshpf, msoAnimEffectMediaPlay, _
, msoAnimTriggerWithPrevious)
With oeff.EffectInformation.PlaySettings
..PlayOnEntry = True
..PauseAnimation = False

And if we moved backward…
Set oshpr = ActivePresentation.Slides(1) _
..Shapes.AddMediaObject(type.wav)
Set oeff = ActivePresentation.Slides(1).TimeLine _
..MainSequence.AddEffect(oshpr, msoAnimEffectMediaPlay, _
, msoAnimTriggerWithPrevious)
With oeff.EffectInformation.PlaySettings
..PlayOnEntry = True
..PauseAnimation = False

TIA ... Greg
 
S

Steve Rindsberg

Steve,
I have had a go at coding the setting and playing of soundeffects but I
can't test it because for some reason the events are no longer being trapped.
I've checked Shyam's buttons are linked to the trap macros, that the add-in
is enabled, that the security settings permit macros and trust VBA projects.
What else might the problem be?

Here's my code for sounding appropriate sound effect. It is based on stuff I
found on the net. Does it look OK?

Not sure ... if you put it in a sub by itself, does it compile and run?

This will though:

With ActivePresentation.Slides(1).Shapes("ShapeNameHere").AnimationSettings
.SoundEffect.ImportFromFile ("C:\Some\SoundFileName.WAV")
.SoundEffect.Play
End With
 

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