Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Insert all slides from a group of presentations into the current presentation

Problem

You have a set of presentations you want to combine into a single PPT file.
While you can manually choose Insert, Slides, From File over and over again, that can get quite tedious, especially if there are many files.

Here are two approaches to solving the problem.

Solution 1 - Insert files from a list

The macro below will read each PPT file name from a list of files in LIST.TXT and for each presentation name it reads, it will insert all slides from that presentation into the current presentation. By creating the LIST.TXT file yourself, you can have the macro insert slides from presentations in multiple folders.

If the LIST.TXT file doesn't exist, the macro creates it and fills it with the names of all the files in the folder specified to by sListFilePath. (And thanks to Doug for his follow-up questions that nudged me into making this clearer.)

Sub InsertFromList()
' Inserts all presentations named in LIST.TXT into current presentation
' in list order
' LIST.TXT must be properly formatted, one full path name per line

    On Error GoTo ErrorHandler

    Dim sListFileName As String
    Dim sListFilePath As String
    Dim iListFileNum As Integer
    Dim sBuf As String

    ' EDIT THESE AS NEEDED
    ' name of file containing files to be inserted
    sListFileName = "LIST.TXT"  

    ' backslash terminated path to filder containing list file:
    sListFilePath = "c:\support\batchinsert\" 

    ' Do we have a file open already?
    If Not Presentations.Count > 0 Then
        Exit Sub
    End If

    ' If LIST.TXT file doesn't exist, create it
    If Len(Dir$(sListFilePath & sListFileName)) = 0 Then
        iListFileNum = FreeFile()
        Open sListFilePath & sListFileName For Output As iListFileNum
        ' get file names
        sBuf = Dir$(sListFilePath & "*.PPT")
        While Not sBuf = ""
            Print #iListFileNum, sBuf
            sBuf = Dir$
        Wend
        Close #iListFileNum
    End If

    iListFileNum = FreeFile()
    Open sListFilePath & sListFileName For Input As iListFileNum
    ' Process the list
    While Not EOF(iListFileNum)
        ' Get a line from the list file
        Line Input #iListFileNum, sBuf

        ' Verify that the file named on the line exists
        If Dir$(sBuf) <> "" Then
            Call ActivePresentation.Slides.InsertFromFile( _
                  sBuf, ActivePresentation.Slides.Count)
        End If
    Wend

    Close #iListFileNum
    MsgBox "DONE!"

NormalExit:
    Exit Sub
ErrorHandler:
    Call MsgBox("Error:" & vbCrLf & Err.Number & vbCrLf & Err.Description, _
                      vbOKOnly, "Error inserting files")
    Resume NormalExit
End Sub

Solution 2 - Insert all slides from all presentations in the same folder

The following code will insert all slides from all presentations in the same folder as the currently active presentation (but won't try to insert slides from the current presentation into itself).

Sub InsertAllSlides()
'  Insert all slides from all presentations in the same folder as this one
'  INTO this one; do not attempt to insert THIS file into itself, though.

    Dim vArray() As String
    Dim x As Long

    ' Change "*.PPT" to "*.PPTX" or whatever if necessary:
    EnumerateFiles ActivePresentation.Path & "\", "*.PPT", vArray

    With ActivePresentation
        For x = 1 To UBound(vArray)
            If Len(vArray(x)) > 0 Then
                .Slides.InsertFromFile vArray(x), .Slides.Count
            End If
        Next
    End With

End Sub

Sub EnumerateFiles(ByVal sDirectory As String, _
    ByVal sFileSpec As String, _
    ByRef vArray As Variant)
    ' collect all files matching the file spec into vArray, an array of strings

    Dim sTemp As String
    ReDim vArray(1 To 1)

    sTemp = Dir$(sDirectory & sFileSpec)
    Do While Len(sTemp) > 0
        ' NOT the "mother ship" ... current presentation
        If sTemp <> ActivePresentation.Name Then
            ReDim Preserve vArray(1 To UBound(vArray) + 1)
            vArray(UBound(vArray)) = sDirectory & sTemp
        End If
        sTemp = Dir$
    Loop

End Sub

Caveat Coder

When you insert slides from another presentation this way, PowerPoint is liable to leave the presentations you've inserted files from open. In some situations, you cannot close these presentations in code. This can cause unwanted side-effects. Beware.

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Insert all slides from a group of presentations into the current presentation
http://www.pptfaq.com/FAQ00746_Insert_all_slides_from_a_group_of_presentations_into_the_current_presentation.htm
Last update 25 January, 2019
Created: