0

I have seen a post like this before but could not add more comments and could not implement the solution. So please do not criticize :) I basically need to open an empty pptx file and give a location of a folder that consists lets say 20 other pptx presentations (text, graphs, images) and add those (automatically) into the opened file. All of the VBA I have tried so far is not working for me so please put comments if you can provide a VBA sample for amateurs like me!

Much appreciated!

As advised by one of the masters here, here is the code I used and replaced the strFPath with the folder I included all the pptx files that I wanted to be inserted into the MASTER presentation pptx file and replaced the strSpec with one of the files from the folder I placed the other files so that it gets inserted but no luck of it working.

Sub Combine_fromFolder() 
    Dim strFPath As String 
    Dim strSpec As String 
    Dim strFileName As String 
    Dim oTarget As Presentation 
    Set oTarget = Application.Presentations.Add(WithWindow:=True) 
    strFPath = "C:\Users\John\Desktop\Test\" ' Edit this
    strSpec = "*.PPTX" 'to include PPT etc use "*.PP*"
    strFileName = Dir$(strFPath & strSpec) 
    While strFileName <> "" 
        oTarget.Slides.InsertFromFile strFileName, oTarget.Slides.Count, 1, 1 
        strFileName = Dir() 
    Wend 
End Sub 
3
  • Much better :-) Now we just need to know how it isn't working. Does it do anything? Are you getting an error? If so, please post the exact error message.
    – CharlieRB
    Mar 23, 2016 at 16:54
  • What's going wrong? Is it adding the slides to the wrong target? Is there an error? etc Mar 23, 2016 at 17:30
  • One possible hitch: if the file containing the code or the file you're inserting slides INTO is in the same folder as the files you want to insert slides FROM, you'll run into trouble. Add a test to make sure that strFileName <> oTarget.Name before the line that does the insertion. Mar 24, 2016 at 17:12

1 Answer 1

0

I could not get the one you have to work. It is rather old, so maybe it is not compatible with the later versions of PowerPoint.

I did find the following VBA at PPTools, Solution 2, which works to do what you described. Only exception, you don't have to change the path because this one uses the folder where the files you want to combine reside.

There are two Subs in this code that must be used together.

  • Open a new presentation file and save it to the folder all the files you want to combine are in (you can move it later)
  • Paste the code into the VBA window
  • Run the InsertAllSlides macro and it will combine them.

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
4
  • Hello Charlie thank you for the help. I have a problem running it probably because I am not doing something right. run the macro and nothing gets combined in the mother ship file :( Could I just record a video and share the youtube link with you to assess?
    – anton86
    Mar 29, 2016 at 9:26
  • Are you opening and saving a new macro enabled presentation in the folder where all the files are? After pasting the code into VBA, did you debug before you ran it? Does it give any error message? You can do the video if you want, but I don't know if it will help unless there is something specific happening.
    – CharlieRB
    Mar 29, 2016 at 11:54
  • Hello, I managed to make it work although i need to ask for help in terms of how to save the layout of the slides being imported?
    – anton86
    Jul 15, 2016 at 13:55
  • Considering the age of this post, I would suggest you create a new question specific to what you need.
    – CharlieRB
    Jul 15, 2016 at 17:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .