Restoring Video Playback in PowerPoint

Restoring Video Playback in PowerPoint

When you insert videos in PowerPoint and then run them in a slide show, the most common way to use them is to play them from the start, wait until they have finished and then move on to the next slide.

You can of course use the Play, Pause, Stop and Seek animation controls to get greater control of your video.

But what happens if you want to leave your slide and then come back to it at some point later to pick up from the video at exactly the same time you left it?

It’s not possible in PowerPoint… unless you use a VBA macro. And we’ve designed one for you to use for free!

Using The Macro

If you’ve never used a VBA macro in PowerPoint before, check out our short tutorial which explains how to insert a macro in PowerPoint for the PC or Mac.

Once the macro is in your presentation you will need to create a few shapes on your slides to use it. The following steps will get you going with a two slide demo and you can download a PowerPoint file in which we’ve already created one:

  1. Create a new presentation with two blank slides
  2. Insert a video into slide 1 and using the PowerPoint Selection Pane (Alt+F10), rename it “Video”
  3. Insert a rectangle on slide 1 and rename it “Go to slide 2”
  4. With the rectangle selected, go to the Insert tab in PowerPoint and select Links / Action
  5. In the Mouse Click tab, select Run Macro and choose the GoToSlide macro
  6. Repeat steps 3 to 5 on slide 2, naming the rectangle “Go to slide 1”
  7. Run your slide show and use the two buttons you created to switch between the two slides and observe the video restarting at the point you left it

 

Video Playback control in PowerPoint with VBA

PowerPoint demo presentation

Download the PowerPoint demo presentation

 

The Macro

' VBA Macro for PowerPoint to restore the playback position of videos in slide show
'----------------------------------------------------------------------------------
' Copyright (c) 2014 YOUpresent Ltd.
' Source code is provide under Creative Commons Attribution License
' This means you must give credit for our original creation in the following form:
' "Includes code created by YOUpresent Ltd. (YOUpresent.co.uk)"
' Commons Deed @ http://creativecommons.org/licenses/by/3.0/
' License Legal @ http://creativecommons.org/licenses/by/3.0/legalcode
'----------------------------------------------------------------------------------
' Purpose : Stores and restores the video playback position of a single video on a
'           slide during the slide show so that it picks up from where it wa left
'           when returning to that slide during the slide show session.
'
' Author : Jamie Garroch
' Date : 07JAN2015
' Website : http://youpresent.co.uk and http://www.gmark.co
'----------------------------------------------------------------------------------

Option Explicit

Public VideoArray() As Single ' two dimensional array : SlideIndex, 0 = VideoPos
Public Const VideoName = "Video"

' Run this whenever the number of slides in the presentation is changed during an editing session
Sub ResetVideoArray()
  End
End Sub

' Main macro for storing and restoring the video playback position during a slide show
Sub GoToSlide(oShp As Shape)
  Dim CurSlide As Integer
  Dim TargetSlide As Integer
  Dim x As Single
  
  ' Ignore errors generated when arrary is first dimensioned or when no video is found
  On Error Resume Next
  
  ' Try to ascertain the upper bound of the video array
  x = UBound(VideoArray, 1)
  
  ' If the above line produced an error then the array has not been dimensioned yet so do it now
  ' with rows equal to the number of slides in the presentation
  If Not Err = 0 Then ReDim VideoArray(1 To ActivePresentation.Slides.Count, 1 To 1): Debug.Print "Array dimensioned": Err.Clear
  
  ' Get the target slide from the clicked shape name
  TargetSlide = CInt(Replace(LCase(oShp.Name), "go to slide ", ""))
  
  ' Get the current slide index in slide show mode
  CurSlide = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
  
  ' Save the video playback position in the array
  VideoArray(CurSlide, 1) = SlideShowWindows(1).View.Player(VideoName).CurrentPosition
  
  ' Go to and restart the target slide (causes the first video frame to be seen momentarily)
  SlideShowWindows(1).View.GoToSlide (TargetSlide)
  
  ' Reset the playback position of the video
  SlideShowWindows(1).View.Player(VideoName).CurrentPosition = VideoArray(TargetSlide, 1)
  
  ' Continue playing the video
  SlideShowWindows(1).View.Player(VideoName).Play
  
End Sub

Need Help?

PowerPoint automation can improve productivity to an amazing degree. If you’d like custom macros developed or an add-in developed that adds your own specified buttons to the PowerPoint ribbon, contact us to discuss your ideas.

Submit a Comment

Your email address will not be published. Required fields are marked *