View Full Version : [SOLVED:] How to Apply this VBA to more than just Slide 3??
Kellaroo
03-09-2022, 08:55 PM
This code works brilliantly for automatically returning the viewer from Slide 3 to 'last 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!
John Wilson
03-10-2022, 02:10 AM
You can check for odd numbers with if i/2 =i\2 then
Paul_Hossler
03-10-2022, 05:25 AM
Two ways, if I understand
Option Explicit
Sub OnSlideShowPageChange()
Dim oPres As Presentation
Set oPres = ActivePresentation
With oPres.SlideShowSettings
.LoopUntilStopped = msoCTrue
.AdvanceMode = ppSlideShowUseSlideTimings
.ShowType = ppShowTypeWindow
.Run
End With
Select Case oPres.SlideShowWindow.View.CurrentShowPosition
'might be more flexible
Case 3, 5, 7, 9
With SlideShowWindows(1).View
.GotoSlide (.LastSlideViewed.SlideIndex), msoFalse
End With
Case Else
Exit Sub
End Select
End Sub
Sub OnSlideShowPageChange_1()
Dim oPres As Presentation
Set oPres = ActivePresentation
With oPres.SlideShowSettings
.LoopUntilStopped = msoCTrue
.AdvanceMode = ppSlideShowUseSlideTimings
.ShowType = ppShowTypeWindow
.Run
End With
'every odd numbered slide
If oPres.SlideShowWindow.View.CurrentShowPosition Mod 2 = 1 Then Exit Sub
With SlideShowWindows(1).View
.GotoSlide (.LastSlideViewed.SlideIndex), msoFalse
End With
End Sub
Kellaroo
03-11-2022, 01:30 AM
All solutions above worked brilliantly : )
@John-Wilson love the simplicity of this fix TY
@Paul_Hossler love the flexibility of the case approach TY This will really help me in the future!
I'm basically trying to eliminate the wheel scroll on my PPTs. During my Zoom classes, my students and I all use the same PPTs and sometimes their itchy trigger fingers hit the wheel scroll :doh: So I'm putting a slide in between each relevant slide that returns viewer to 'LastSlideViewed' (effectively preventing the wheel scroll).
Master & Sage, Thank You for Your Time
Kellaroo
10-10-2022, 10:29 PM
I find myself returning to this thread with new problem.
How can I make this VBA apply to only one open PPT file/window.
It works great for the PPT that I use every day, but unfortunately I often use more than one PPT at a time. It disrupts the other open PPTs.
Kellaroo
10-10-2022, 10:32 PM
I tried to make it specific to the title of the PPTM.
Here my PPTM file is titled "X" but it doesn't stop the disruptions. I just want the main PPTM to not go to the Case slides, but allow the other PPTs to go wherever.
Sub OnSlideShowPageChange()
Dim oPres As Presentation
Set oPres = Presentations("X.pptm")
With oPres.SlideShowSettings
.LoopUntilStopped = msoCTrue
.AdvanceMode = ppSlideShowUseSlideTimings
.ShowType = ppShowTypeWindow
.Run
End With
Select Case oPres.SlideShowWindow.View.CurrentShowPosition
'might be more flexible
Case 3, 5, 7, 9
With oPres
With SlideShowWindows(1).View
.GotoSlide (.LastSlideViewed.slideIndex), msoFalse
End With
End With
Case Else
Exit Sub
End Select
End Sub
Kellaroo
10-10-2022, 10:34 PM
I've tried to identify the correct PPT with SlideShowWindows(2) but I don't quite understand what those numbers indicate. How do I know which PPT is which Window number?
Kellaroo
10-11-2022, 11:14 PM
I figured out a fix (not sure it's the best fix) but...
I changed the 14th line from
"With SlideShowWindows(1).View"
to
"With oPres.SlideShowWindow.View"
I'm not exactly sure why this original part at the top doesn't suffice in making it PPT specific:
"Set oPres = Presentations("X.pptm")
With oPres.SlideShowSettings"
but it's working now : )
John Wilson
10-12-2022, 02:16 AM
You could also try to make it only run with a specific named presentation
Sub OnSlideShowPageChange(sw As SlideShowWindow)
If sw.Presentation.Name <> "whateva.pptx" Then Exit Sub
Kellaroo
10-12-2022, 06:49 PM
Hi John! Always good to hear from you.
I admit, I couldn't get this to work. I suspect it's the better method though.
I input my PPTm title into the "whateva" and changed "pptx" to "pptm" but to no avail.
So basically the "<>" means that if the file name is different in any way then it aborts the sub, is that right?
What does the "sw." mean?
Aussiebear
10-13-2022, 02:25 PM
sw is the "variable" name for SlideShowWindow as evidenced in the first line of code in John's post (#9)
Kellaroo
10-13-2022, 11:08 PM
Thanks for clarification Aussiebear!
I'm so accustomed to not understanding, that I sometimes overlook things I could actually have figure out : )
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.