Consulting

Results 1 to 12 of 12

Thread: How to Apply this VBA to more than just Slide 3??

  1. #1
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location

    How to Apply this VBA to more than just Slide 3??

    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!
    Last edited by Kellaroo; 03-09-2022 at 09:17 PM.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    You can check for odd numbers with if i/2 =i\2 then
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location
    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 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

  5. #5
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location
    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.

  6. #6
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location
    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

  7. #7
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location
    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?

  8. #8
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location
    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 : )

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  10. #10
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location
    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?

  11. #11
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    4,997
    Location
    sw is the "variable" name for SlideShowWindow as evidenced in the first line of code in John's post (#9)
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  12. #12
    VBAX Regular
    Joined
    Feb 2022
    Posts
    37
    Location
    Thanks for clarification Aussiebear!
    I'm so accustomed to not understanding, that I sometimes overlook things I could actually have figure out : )

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •