Update Media Properties in a PowerPoint Presentation
Getting Started with Media in PowerPoint: Learn how to display and update media properties in a Microsoft PowerPoint 2010 presentation.
Last modified: May 10, 2011
Applies to: Office 2010 | PowerPoint 2010 | VBA
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. To emphasize or control media that you use in your presentations, you can adjust, display, or update various properties associated with that media. In this topic, you insert a video into a Microsoft PowerPoint 2010 presentation and then programmatically display and update the properties of that video. To complete this task, you must do the following:
In this task, you insert a sample video file into the PowerPoint 2010 presentation.
To insert a video file
Download the PowerPoint 2003 sample video.
Start PowerPoint 2010.
Delete the shapes from the first slide.
On the Insert menu, click Video, and then click Video from File.
Navigate to the sample video file and then click Insert.
Resize the video so that you can see it better, and then play it to make sure that there are no problems. Note the length, the beginning and ending times, and the volume of the video.
In this task, you open the Visual Basic Editor, and then insert a standard module.
To add a standard module to a PowerPoint presentation
On the Developer tab, click Visual Basic to open the Visual Basic Editor.
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.
On the Insert menu, click Module. This adds Module1 to the Projects pane on the left side of the Visual Basic Editor.
In this task, you add Microsoft Visual Basic for Applications (VBA) code that displays several properties related to the sample video, and then updates some of those properties.
To add code to the Visual Basic Editor
In the Projects pane, click Module1.
Paste or type the following code into the module window.
Sub MediaFormatInfo() 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 DisplayMediaFormatInfo shp ' Work with the MediaFormat property: With shp.MediaFormat ' Modify the values that can be modified: ' Start at 2 seconds, end at 5 seconds, ' fade in and out for 1/2 second: .StartPoint = 2000 .EndPoint = 5000 .FadeInDuration = 500 .FadeOutDuration = 500 ' Ensure the video isn't muted, and ' that the volume is lower than max: .Muted = False .Volume = 0.25 End With Debug.Print "================" DisplayMediaFormatInfo shp End If Next shp End Sub Private Sub DisplayMediaFormatInfo(shp As Shape) With shp.MediaFormat ' Retrieve all the useful properties: Debug.Print vbTab & "AudioCompressionType: " & .AudioCompressionType Debug.Print vbTab & "AudioSamplingRate: " & .AudioSamplingRate Debug.Print vbTab & "EndPoint: " & .EndPoint Debug.Print vbTab & "FadeInDuration: " & .FadeInDuration Debug.Print vbTab & "FadeOutDuration: " & .FadeOutDuration Debug.Print vbTab & "IsEmbedded: " & .IsEmbedded Debug.Print vbTab & "IsLinked: " & .IsLinked Debug.Print vbTab & "Length: " & .Length Debug.Print vbTab & "Muted: " & .Muted Debug.Print vbTab & "ResamplingStatus: " & .ResamplingStatus Debug.Print vbTab & "SampleHeight: " & .SampleHeight Debug.Print vbTab & "SampleWidth: " & .SampleWidth Debug.Print vbTab & "StartPoint: " & .StartPoint Debug.Print vbTab & "VideoCompressionType: " & .VideoCompressionType Debug.Print vbTab & "VideoFrameRate: " & .VideoFrameRate Debug.Print vbTab & "Volume: " & .Volume End With End Sub
In this task, you run the VBA code. The code displays the property values in the Immediate window.
To run the code
If you do not see the Immediate window, click View, and then click Immediate Window.
To single step through the code, place the cursor in the MediaFormatInfo procedure, and then press F8. Observe the results in the Immediate window as you step through the code.
After you run all of the code, press Alt + Q to close the Visual Basic Editor and move back to the presentation.
Run the video. Note the changes in duration and volume of the video.