PowerPoint 2010 VBA- Add an audio File or Video File

Const videoFileName As String = "C:\Users\Public\Videos\Sample Videos\Bee.wmv"
Const audioFileName As String = "C:\Users\Public\Music\Sample Music\Happy Birthday.mp3"
Sub AddMedia()
    With ActivePresentation.Slides(1).Shapes
        Dim shp As Shape
        ' Set only one of height and width--PowerPoint will maintain the correct
        ' aspect ratio for the video. This video is linked (as opposed to embedded).
        Set shp = .AddMediaObject2(videoFileName, msoTrue, msoFalse, 10, 10, 320)
        DisplayMediaInfo shp

        ' This audio is embedded, not linked.
        Set shp = .AddMediaObject2(audioFileName, msoFalse, msoTrue, 350, 10)
        DisplayMediaInfo shp
    End With
End Sub

Private Sub DisplayMediaInfo(shp As Shape)
    If shp.Type = msoMedia Then
        Debug.Print "Embedded: " & shp.MediaFormat.IsEmbedded
        Debug.Print "Linked: " & shp.MediaFormat.IsLinked
    End If
End Sub

Leave a Reply

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