Search code examples
vbapowerpoint

How to Apply this VBA to Several Slides in PowerPoint?


This code works brilliantly for automatically returning the viewer from Slide 3 to 'previous slide viewed' but it seems to only be applicable to one slide. For example, I want to apply it to every odd numbered slide in index (ie 3,5,7,9,11, etc) but then it stops working...

Sub OnSlideShowPageChange()
With ActivePresentation.SlideShowSettings
    .LoopUntilStopped = msoCTrue
    .AdvanceMode = ppSlideShowUseSlideTimings
    .ShowType = ppShowTypeWindow
    .Run
   End With
   
    Dim i As Integer
    i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
    If Not i = 3 Then Exit Sub
    With SlideShowWindows(1).View

     .GotoSlide (.LastSlideViewed.SlideIndex), msoFalse
    End With

End Sub

Any help would be greatly appreciated!


Solution

  • So I didn't code vba for some years but if I understand your snippet correctly it e.g. stops the presentation from advancing from page 2 to page 3 (by sending the presentation to the previous page)

    if you now want to apply this to every odd page you could rewrite line 11 to:

    If Not i Mod 2 > 0 Then Exit Sub
    

    it works for me. please correct me if I understood the task wrong.