PowerPoint VBA - Insert Audio Clips to each slide

Posted on 2012-09-02
Last Modified: 2012-09-18
I need to automate this. I have a series of short audio clips in a folder. Each approx 20 secs. I want to Insert > Audio > From File on each slide sequentially. It can be on a New PowerPoint presentation.
And set the audio clip to:
Start With Previous
Stop After 1 Slide.

My Excel VBA is at a high level but is NIL on PowerPoint.

Thanks experts!
Question by:hindersaliva
    LVL 23

    Accepted Solution

    This should get you close. Obviously change the folder path and the filespec if they are not mp3 files. Some of the code is adapted from Steve Rindsberg's PPTFAQ

    Sub Audio_In()
        Dim rayFileList() As String
        Dim FolderPath As String
        Dim FileSpec
        Dim strTemp As String
        Dim x As Long
        Dim opres As Presentation
        Set opres = Presentations.Add(WithWindow:=True)
        ' EDIT THESE to suit your situation
        FolderPath = "c:\Users\John\Desktop\Music\"  ' Note: MUST end in \
        FileSpec = "*.mp3"
        ' END OF EDITS
        ReDim rayFileList(1 To 1) As String
        strTemp = Dir$(FolderPath & FileSpec)
        While strTemp <> ""
            rayFileList(UBound(rayFileList)) = FolderPath & strTemp
            ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As String
            strTemp = Dir
        If UBound(rayFileList) > 1 Then
            For x = 1 To UBound(rayFileList) - 1
                Call InsertMe(rayFileList(x), opres)
            Next x
        End If
    End Sub
    Sub InsertMe(filePath As String, opres As Presentation)
    Dim omusic As Shape
    Dim osld As Slide
    Dim oeff As Effect
    On Error Resume Next
    Set osld = opres.Slides.Add(opres.Slides.Count + 1, ppLayoutTitleOnly)
    Set omusic = osld.Shapes.AddMediaObject2(filePath, Left:=10, Top:=10, Width:=20, Height:=20)
    With omusic
    Set oeff = osld.TimeLine.MainSequence.AddEffect(omusic, msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious)
    oeff.EffectInformation.PlaySettings.StopAfterSlides = 1
    End With
    End Sub

    Open in new window


    Author Closing Comment

    I haven't tested it yet. But I know JSRW's solutions are good.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Outline From PowerPoint 2010 it is possible to have shapes appear in front of video, in earlier versions video always played in front of other shapes. This means it is possible to have captions animated to appear in front of video. Users who h…
    Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
    The viewer will learn how to edit the master slide. They will also learn how to combine multiple themes into one master slide to use them in their presentation.
    The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now