none
VBA : Changing current slide RRS feed

  • Question

  • Hello, 

    I am trying to write a macro that change the slide show slide back to slide 1.

    I have tried to use this like : SlideShowWindows(1).View.GotoSlide (1)

    But I get an error when I run it in the VBA code view window : "SlideShowWindows (unknown member) : Integer out of range. 1 is not in valid 

    range of 1 to 0.

    Thanks for any help, 

    Tamir


    • Edited by Tamir Einy Wednesday, October 10, 2012 8:50 AM
    Wednesday, October 10, 2012 8:49 AM

Answers

All replies

  • Hi Tamir,

    Thank you for posting in the MSDN Forum.

    I've tried to adapt the code of Sub Play() in this thread into below, and it works fine.

    Sub Play()
        'Count slides in this presentation.
        Dim slideCount As Integer
        slideCount = ActivePresentation.Slides.Count
        'Display the presentation.
        ActivePresentation.SlideShowSettings.Run
        
        Dim i As Integer 'i used as slides' index.
        For i = 1 To slideCount Step 1
               Pause (1) 'pause for 1 sec.
               ActivePresentation.SlideShowWindow.View.Next
        Next i
        ActivePresentation.SlideShowWindow.View.GotoSlide (1)
        'ActivePresentation.SlideShowWindow.View.Exit
        
    End Sub

    In your post you've mentioned that

    But I get an error when I run it in the VBA code view window : "SlideShowWindows (unknown member) : Integer out of range. 1 is not in valid

    I think this is because there's no SlideShowWindow when the code run to this line. Could you please post all your code here for further troubleshooting?

    I look forward to your reply.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Saturday, October 13, 2012 10:01 AM
    Moderator
  • Hi Quist, 

    Thanks again for helping out!

    I am trying to run this code with out pressing Play button at the VBE,

    Here is the code that run under slide3

    Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
        If SSW.View.CurrentShowPosition = 3 Then
            Call DelayAndAdvance
        End If
    End Sub

    Public Sub Pause(sinSeconds As Single)

        Dim sinStartTime As Single
        Dim sinFinishTime As Single

        'Get the current number of seconds since the beginning of the day
        sinStartTime = Timer
        sinFinishTime = sinStartTime + sinSeconds

        'Adjust for midnight
        If sinFinishTime > 86400 Then sinFinishTime = sinFinishTime - 86400

        Do Until Timer > sinFinishTime
              DoEvents
        Loop

    End Sub


    Sub DelayAndAdvance()
     Pause (2.5)
       ' SlideShowWindows(Win_IND).View.GotoSlide(Which)
    ActivePresentation.SlideShowWindow(1).View.GotoSlide (1)
    End Sub

    Wait to hear you input, 

    Best, 

    Tamir

                            
    Saturday, October 13, 2012 11:06 AM
  • Hi Tamir,

    Thank you for you last reply.

    Just as I've mentioned in my last reply. If you want to get the code compile, you'll need to change

    ActivePresentation.SlideShowWindow(1).View.GotoSlide (1) 'Syntax Error.

    into

    ActivePresentation.SlideShowWindow.View.GotoSlide (1)

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 17, 2012 9:58 AM
    Moderator
  • Hi Quist,

    Thanks for your answer.

    I have tried the revised line and I still get the same error at the VBE.

    Here is my problem :

    When I run the code (even that i get the error) and go to slide show it works well.

    But if i just open the power point and go to slide show nothing works.

    Any reasons?

    By the way if you want i can upload the file,

    Thanks,

    Tamir

    Wednesday, October 17, 2012 10:31 AM
  • Hi Tamir,

    Thank you for your last reply.

    It will be quite helpful for troubleshooting if you can upload the file. 

    I look forward to your reply.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 17, 2012 10:43 AM
    Moderator
  • Hi Quist,

    Thanks for your fast reply.

    Here is the link to the file :

    https://skydrive.live.com/redir?resid=243C74A8CF7D937D!173&authkey=!AFhajbOBBd8PtCo

    Looking forward for your solution,

    Tamir

    Wednesday, October 17, 2012 11:08 AM
  • Hi Tamir,

    Sorry for the late in relpy.

    I've figured out the below code for you. Please check it.

    Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
        If SSW.View.CurrentShowPosition = 3 Then
            Call DelayAndAdvance(SSW)
        End If
    End Sub
    ''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Sub DelayAndAdvance(ByVal SSW As SlideShowWindow)
        Pause (2.5)
        SSW.View.GotoSlide (1)
    End Sub

    This snippet of code works fine on my machine. 

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us


    Saturday, October 20, 2012 7:37 PM
    Moderator
  • Sorry Quist but it doesn't work, 

    Please pay attention that after adding the code and saving it and maybe running, I close the VBE and then it works, but If I close power point and then re-open it doesn't.

    Any solution?  :(

    Thanks for you great dedication, 

    Tamir

    Saturday, October 20, 2012 8:06 PM
  • Hi Tamir,

    I've found the solution on this page: http://www.pptfaq.com/FAQ01152_OnSlideShowPageChange_event_does_not_fire.htm

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Sunday, October 21, 2012 6:50 AM
    Moderator
  • Hi Quist, 

    Now it's working well!

    Thanks a lot!! 

    Tamir

    Sunday, October 21, 2012 7:59 AM