Programmatically Create Video from PowerPoint Slide Show

Office Quick Note banner

Getting Started with Media in PowerPoint: Learn how to create a video clip from Microsoft PowerPoint 2010 slides.

Applies to: Office 2010 | PowerPoint 2010 | VBA

In this article
Download and Install a Sample PowerPoint Presentation
Add a Standard Module to the Visual Basic Editor
Add the Code to the Visual Basic Editor
Run the Code
Next Steps

Published:   April 2011

Provided by:    Frank Rice, Microsoft Corporation

Instead of asking users to click through your slide presentation, you can create a video of the presentation and then ask users to view the video. In this topic, you programmatically create a video from the slides in your presentation. To complete this task, you must do the following:

  • Download and Install a Sample PowerPoint Presentation

  • Add a Standard Module to the Visual Basic Editor

  • Add the Code to the Visual Basic Editor

  • Run the Code

Download and Install a Sample PowerPoint Presentation

In this task, you download and install a sample PowerPoint presentation to use in the rest of this Quick Note.

To install the sample PowerPoint presentation

  1. Open PowerPoint 2002 Sample: Presentation for a Kiosk, and then click Download.

  2. When asked whether to run or save the file, click Run.

  3. In the Install Now dialog box, click Yes, and then click Yes to the license agreement.

  4. In the next dialog box, click Browse, specify a location to save the file, and then click OK.

  5. Click OK in the installation complete dialog box.

Add a Standard Module to the Visual Basic Editor

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

To add a standard module to a PowerPoint presentation

  1. Browse to the download location that you specified earlier, and then double-click ppKiosk.ppt to open it.

  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 code to the Visual Basic Editor.

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 TestCreateSampleVideo()
        ' Change the file path and name as required.
        CreateSampleVideo ActivePresentation, "C:\TEMP\Video.wmv"
    End Sub
    
    Sub CreateSampleVideo(pres As Presentation, fileName As String)
        ' Presentation.CreateVideo does its work asynchronously.
        ' You can use the Presentation.CreateVideoStatus property
        ' to periodically check the status, and react accordingly.
    
        pres.CreateVideo fileName, DefaultSlideDuration:=1, VertResolution:=480
    
        ' Now wait for the conversion to be complete:
        Do
            ' Don't tie up the user interface; add DoEvents
            ' to give the mouse and keyboard time to keep up.
            DoEvents
            Select Case pres.CreateVideoStatus
                Case PpMediaTaskStatus.ppMediaTaskStatusDone
                    MsgBox "Conversion complete!"
                    Exit Do
                Case PpMediaTaskStatus.ppMediaTaskStatusFailed
                    MsgBox "Conversion failed!"
                    Exit Do
                Case PpMediaTaskStatus.ppMediaTaskStatusInProgress
                    Debug.Print "Conversion in progress"
                Case PpMediaTaskStatus.ppMediaTaskStatusNone
                    ' You'll get this value when you ask for the status 
                    ' and no conversion is happening or has completed.
                Case PpMediaTaskStatus.ppMediaTaskStatusQueued
                    Debug.Print "Conversion queued"
            End Select
        Loop
    End Sub
    
  3. Close the Visual Basic Editor.

In this procedure, the CreateVideo method of the Presentation object does all of the work. The remainder of the code provides conversion status.

In addition to a file name, the CreateVideo method accepts the following parameters:

  • UseTimingsAndNarration indicates whether to use the timings and narrations for the presentation that you have supplied. If false, the conversion ignores the information. The default value is true.

  • DefaultSlideDuration indicates the default timing for each slide, if you have not specified a timing, or if you set UseTimingsAndNarration to false. The default value is 5 seconds.

  • VertResolution indicates the vertical resolution for your video. The default is 720. Standard options include 720, 480, and 240, although you can specify any reasonable value. For example, you could specify 200, even though it is not a standard vertical resolution.

  • FramesPerSecond indicates the number of frames per second in the output video. The default value is 30; do not change this value unless you have a very good reason to change it.

  • Quality indicates a relative quality of the video; the default value is 85. The larger the number, the larger the output and the longer it takes to create the video. Do not change this value unless you have a very good reason to change it. If you set the value to a low number, you will see a definite degradation in output quality.

Run the Code

In this task, you run the code that creates the video from the slides in the presentation.

To run the code

  • On the Developers tab, click Macros, select TestCreateSampleVideo, and then click Run.

    Navigate to the new video and run it.

Next Steps