Resampling Videos in PowerPoint

Office Quick Note banner

Getting Started with Media in PowerPoint: Learn how to programmatically increase the size of a video in a Microsoft PowerPoint 2010 presentation by using resampling.

Applies to: Office 2010 | PowerPoint 2010 | VBA

In this article
Add a Sample Video File to a Presentation
Add a Standard Module to a PowerPoint Presentation
Add the Code to the Visual Basic Editor
Run the Code
Next Steps

Published:   April 2011

Provided by:    Frank Rice, Microsoft Corporation

Adding high-quality videos to a slide presentation can greatly increase the impact that it has on your viewers. Videos can come in various sizes and resolutions. You can Increase or decrease the size and resolution of a video or other graphic by using a process called resampling. In this topic, you add a video to a new Microsoft PowerPoint 2010 slide and then programmatically use resampling to increase its size while maintaining much of its resolution. To complete this task, you must do the following:

  • Add a Sample Video File to a Presentation

  • Add a Standard Module to a PowerPoint Presentation

  • Add the Code to the Visual Basic Editor

  • Run the Code

Add a Sample Video File to a Presentation

In this task, you insert a sample video file into a PowerPoint 2010 presentation.

To insert a video file

  1. Download the PowerPoint 2003 sample video.

  2. Start PowerPoint 2010.

  3. On the Insert menu, click Video, and then click Video from File.

  4. Navigate to the sample video file and then click Insert.

After you add the video, play it to make sure that there are no problems.

Add a Standard Module to a PowerPoint Presentation

In this task, you open a PowerPoint 2010 presentation, open the Visual Basic Editor, and then insert a standard module.

To add a standard module to a PowerPoint presentation

  1. Start PowerPoint 2010.

  2. On the Developer tab, click Visual Basic to open the Visual Basic Editor.

    Note

    If you do not see the Developer tab in PowerPoint, click the File tab, and then click Options. In the categories pane, click Popular, select Show Developer tab in the Ribbon, and then click OK.

  3. On the Insert menu, click Module. This adds Module1 to the Projects pane on the left side of the Visual Basic Editor.

Add the Code to the Visual Basic Editor

In this task, you add programming code that uses resampling to change the resolution of a video on slide 1. In this particular instance, the code resets the resolution and then changes the size of the video.

To add code to the Visual Basic Editor

  1. In the Projects pane, click Module1.

  2. Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.

    Sub ResampleDemo()
        ' This code works through every shape on the
        ' first slide in the presentation, and for each
        ' video it finds, resamples the video to 240x320. If
        ' the resampling succeeds, the code resizes the video
        ' shape to match the new resolution.
        Dim shp As Shape
        For Each shp In ActivePresentation.Slides(1).Shapes
            ' Is it a media shape?
            If shp.Type = msoMedia Then
                Debug.Print "Media Element: " & shp.Name
    
                Dim newWidth As Integer
                Dim newHeight As Integer
                newHeight = 240
                newWidth = 320
                ' You can specify other parameters, as well, indicating
                ' the video frame rate, the audio sampling rate, and the
                ' video bit rate. For now, just resample and reset
                ' the resolution--the lower the resolution, the smaller the video
                ' content.
                shp.MediaFormat.Resample True, newHeight, newWidth
                Do
                    DoEvents
                    Pause 1
                    Debug.Print "Resample status: " & shp.MediaFormat.ResamplingStatus
                Loop While shp.MediaFormat.ResamplingStatus = ppMediaTaskStatusInProgress
                Debug.Print "Resample status: " & shp.MediaFormat.ResamplingStatus
                If shp.MediaFormat.ResamplingStatus = ppMediaTaskStatusDone Then
                    shp.Width = newWidth
                    shp.Height = newHeight
                End If
            End If
        Next shp
    End Sub
    
    Function Pause(numberOfSeconds As Variant)
        Dim startTime, endTime As Variant
    
        startTime = Timer
        endTime = startTime + numberOfSeconds
    
        Do While Timer < endTime
            DoEvents
        Loop
    End Function
    
  3. Close the Visual Basic Editor.

Run the Code

In this task, you run the VBA code that resets the resolution of the video and then resizes it.

To run the code

  • On the Developers tab, click Macros, select ResampleDemo, and then click Run. Notice that the code resizes the video, but that the resolution is still comparable to that of the original. Note that the code also writes resampling information to the Visual Basic Editor Immediate window.

In the following procedure, you step through the code and watch how each line modifies the video. The best way to see the code in action is to place the Visual Basic Editor window next to the PowerPoint window.

To step through the code

  1. Delete the existing video from slide 1 and then reinsert a new version.

  2. Open the Visual Basic Editor and drag it to the right side of your monitor.

  3. Drag the PowerPoint window to the left side of the monitor and adjust both windows until you can see them both.

  4. Place the cursor in the ResampleDemo procedure and then press F8 to step through the code line-by-line. Watch the results in the PowerPoint window.

Next Steps