Search code examples
vbapowerpointwait

How to add delay before going to next slide in PPT using VBA


The Slide Show has to be "Browsed at a Kiosk". I don't want to give the users the option to go to the next slide by pressing the next key or anything like that.

It's a quiz game. By pressing the correct option the following code activates:

Sub CorrectAnswer()
Correct.Caption = (Correct.Caption) + 1
Percentage.Caption = (Percentage.Caption) + 5
MsgBox "That was the correct answer!", vbInformation + vbApplicationModal, "FOLK Quiz"
ActivePresentation.SlideShowWindow.View.Next
End Sub

The user presses any one of the four options. There's a trigger for each box. When the trigger is activated one of the box turns green and the rest turns red. I've done this by using Animations.

Then I want to go to the next slide after a few seconds after the animation... but how is this possible? Is there any way to add a delay in going to the next slide in VBA?


Solution

  • You need to add some wait time before going to next slide. It is posible by using Application.Wait. Your code then will look like this:

    Sub CorrectAnswer()
    
      Correct.Caption = (Correct.Caption) + 1
    
      Percentage.Caption = (Percentage.Caption) + 5
    
      MsgBox "That was the correct answer!", vbInformation + _
                                             vbApplicationModal, "FOLK Quiz"
      lag = 3 
      start = Timer
    
      While Timer < Start + lag
            DoEvents
      Wend
    
    
      'Application.Wait(Now + TimeValue("0:00:03")) 'This adds 3 sec delay in ms VBA
    
      ActivePresentation.SlideShowWindow.View.Next
    
    End Sub