OnSlideShowPageChange not running in presentation

powerpoint vba events
powerpoint vba next slide

I have been tasked with building an automated powerpoint to show new employees during onboarding. I decided to use the text-to-speech function of PPT to narrate the show. I came to the realization that this would require code, so I searched and found some code to use. When I start it within VBA, it runs. However, when in presentation mode, it doesn't fire the code. After hours of searching, I can't seem to find what I've done wrong. Any help is greatly appreciated.

Function SpeakThis(myPhrase As String)
Dim oSpeaker As New SpeechLib.SpVoice

'Set speech properties
oSpeaker.Volume = 100 ' percent
oSpeaker.Rate = 0.1 ' multiplier
oSpeaker.SynchronousSpeakTimeout = 1
oSpeaker.AlertBoundary = SVEWordBoundary

If Not myPhrase = "" Then oSpeaker.Speak myPhrase, SVSFDefault
End Function

Sub OnSlideShowPageChange()
Dim text As String
Dim intSlide As Integer
intSlide = ActiveWindow.Selection.SlideRange.SlideIndex

text = ActivePresentation.Slides(intSlide).NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.text
SpeakThis text
End Sub

To get the current slide index, you can use the following:

  1. In Slide View mode: ActiveWindow.View.Slide.SlideIndex
  2. In Slide Show mode: ActivePresentation.SlideShowWindow.View.Slide.SlideIndex

For this to work in presentation mode, change

intSlide = ActiveWindow.Selection.SlideRange.SlideIndex


intSlide = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex

Note that this throws an error if not in presentation mode.

EDIT: In simplified form, you could also do this:

Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)

    SpeakThis Wn.View.Slide.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.text

End Sub

[SOLVED] Issues with "OnSlideShowPageChange", So, I created a file with a sub "OnSlideShowPageChange" that the messages appears when I run the presentation again. I am using PPT 2016 on Windows 10. the presentation from within PowerPoint, but not when you  If you are interested to run a custom code when the slide changes during the slideshow, then here is a VBA script snippet that you can modify to run your own code.. Basically what we are going to do is to use the OnSlideShowPageChange() event at the presentation level to detect when the slide is changed during a slideshow in PowerPoint 2010, but you can also use this snippet in PowerPoint 2007

Here I introduce MY work-around which can meet what you want.

Actually, you can save above TTS sound into an .wav file which can be inserted and played on entering each slide. Since you want to play some narration sound on each slide, I suggest you to convert all the notes into .wav files and insert them as normal audio effects.

To automate the process, I wrote some code.

First, to save each note in an .wav file (given the slide index)

'save the slide's note in a .wav file
'You need to add reference to 'Microsoft Speech Object Library' (*required*)
Function SaveTTSWav(idx As Long)
    Const SAFT48kHz16BitStereo = 39
    Const SSFMCreateForWrite = 3
    Dim oSpeaker As New SpeechLib.SpVoice
    Dim oStream As New SpeechLib.SpFileStream

    oStream.Format.Type = SAFT48kHz16BitStereo
    'filename to save: ex) note1.wav
    oStream.Open ActivePresentation.Path & "\note" & idx & ".wav", SSFMCreateForWrite, False
    oSpeaker.Volume = 100   '%
    oSpeaker.Rate = 1       '1x speed
    oSpeaker.SynchronousSpeakTimeout = 1
    oSpeaker.AlertBoundary = SVEWordBoundary
    Set oSpeaker.AudioOutputStream = oStream

    oSpeaker.Speak ActivePresentation.Slides(idx).NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.text, SVSFNLPSpeakPunc
End Function

Then, Insert the 'note(X).wav' files in each slide and add animation effects to them:

'insert the .wav and make it play automatically
Function AddTTSMedia(idx As Long)
    Dim sld As Slide
    Dim shp As Shape
    Dim eft As Effect

    Dim wavfile As String

    wavfile = ActivePresentation.Path & "\note" & idx & ".wav"
    If Len(Dir(wavfile)) = 0 Then Exit Function
    Set sld = ActivePresentation.Slides(idx)
    Set shp = sld.Shapes.AddMediaObject2(wavfile, False, True, 0, 0, 20, 20)
    'shp.Name = Mid(wavfile, InStrRev(wavfile, "\") + 1) '.wav filename
    Set eft = sld.TimeLine.MainSequence.AddEffect(shp, msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious)
    eft.MoveTo 1    'make it the first effect
    With eft.EffectInformation.PlaySettings 'shp.AnimationSettings.PlaySettings
        .HideWhileNotPlaying = True
        .PauseAnimation = False
        .PlayOnEntry = True
        .StopAfterSlides = 1
    End With
    'Kill wavfile
End Function

Finally, make it happen on every slide:

Sub Add_TTS_Notes()
    Dim sld As Slide

    'Remove previously inserted note sounds

    For Each sld In ActivePresentation.Slides
        'save the note to an .wav file
        SaveTTSWav sld.SlideIndex
        'add the .wav file onto the slide
        AddTTSMedia sld.SlideIndex
    Next sld
End Sub

In addition, if you want to cancel and remove all note sounds from your presentation, you can run the following code manually:

'remove all .wav media(s) in each slide
Sub RemoveNoteWav()
    Dim sld As Slide
    Dim i As Long
    For Each sld In ActivePresentation.Slides
        For i = sld.Shapes.Count To 1 Step -1
            If sld.Shapes(i).Name Like "note*.wav" Then sld.Shapes(i).Delete
        Next i
    Next sld
End Sub

All you have to do is to copy all codes above onto your PPT's VBE editor and to run the main macro named "Add_TTS_Notes". It'll take some time to save some TTS sound files.

It will save the notes on all slides in .wav files, insert them on their slides and make them play automatically on each slide. After the job, you can remove VBA codes and save your ppt file as a .pptx or .ppsx which is more handy than a .pptm file since it doesn't require any security agreement.

OnSlideShowPageChange event does not fire, From the PowerPoint FAQ: OnSlideShowPageChange event does not fire. when run from within VBA or when you launch the presentation from within PowerPoint, but not when you  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more OnSlideShowPageChange not running in presentation

I'm using PowerPoint 2016, and in my case, I've needed to modify Konahn's codes as below in SaveTTSWav function.

'Dim oSpeaker As New SpeechLib.SpVoice

Dim oSpeaker As Object Set

oSpeaker = CreateObject("SAPI.Spvoice")


'Dim oStream As New SpeechLib.SpFileStream

Dim oStream As Object Set

oStream = CreateObject("SAPI.SpFileStream")

OnSlideShowPage Macro is not working on PowerPoint for Mac , How can I run it on Mac with no problem? Sub OnSlideShowPageChange(​ByVal SSW As  Run VBA macro at a particular slide Microsoft PowerPoint fires the OnSlideShowPageChange() event for every slide that is shown during the slide show. You can use this facility to call any macro when certain slides are displayed.

OnSlideShowPageChange not running in presentation, OnSlideShowPageChange not running in presentation. powerpoint vba events powerpoint vba next slide. I have been  The OnSlideShowPageChange event doesn’t fire from a macro-enabled slide show file (.ppsm or .pps). To overcome this limitation, we can trick PowerPoint into initialising the pseudo events by adding any Active-X control from the Developer tab of the PowerPoint ribbon to your slide (add it to the off-slide workspace to avoid seeing it during the slide show).

OnSlideShowPageChange not running in presentation, SlideIndex Note that this throws an error if not in presentation mode. EDIT: In simplified form, you could also do this: Sub  What this code is doing is that as the presentation runs when the current position of the presentation reaches slide 2,3 etc it will then run the code attached to that slide. Here i used a small text box that isn't actually on the slide and put a starting date in.

Macros doesn't load on powerpoint startup, I've done a lot of VBA but not with PowerPoint so I don't have the full answer. However, I can see that  OnSlideShowPageChange : OnSlideShowPageChange(ByVal Wn As SlideShowWindow) Occurs after showing the new slide. This is an auto-macro and does not require any object to be declared. It is fired even when the presentation that hosts these event handlers is not in slide show mode. 2016, 2013, 2010, 2007, 2003, 2002, 2000: OnSlideShowTerminate

  • Ahh, I see. This solved it, thank you. However I now ran into another problem. It narrates the next slide's notes before actually changing to that slide, should I use the SlideShowNextSlide event instead? PS, I did give this an upvote but my reputation is too low to show it.
  • SlideShowNextSlide would have the same behavior. From the documentation: "occurs immediately before the transition to the next slide."
  • It's not much of a workaround, but you could change this to a regular subroutine and assign it to an action button on the slide itself.
  • This worked nicely. Thank you. I upvoted, but again, my rep is too low to show this. However, I didn't mark this as the answer since the original question was answered above, and this answers a secondary question.
  • The each first line is commented (deactivated) by ' character from Konanh's code.