0
votes

The goal of my effort is to have a VBA macro that will consolidate a number of PPT presentations into a single PPT presentation. The component presentations that are to be combined are in a number of locations. This seems to be a crucial factor. I found a very good 'almost' solution, but it was based on all of the component presentations being in a single folder. I was able to modify the example, but ActivePresentation.Slides.InsertFromFile will only function if the path to a component presentation is hardcoded. I need this to be data-driven. When I try to reference a variable containing the path, ActivePresentation.Slides.InsertFromFile fails with the error "Error inserting files Error: -2147483640 Powerpoint could not open the file".

Any assistance to get this running by passing the component path as a variable would be very appreciated. Thanks, Jack

The contents of the MANIFEST.txt file are the two lines:
topic-1/control-structures.pptm
topic-2/cursors.pptm

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

    On Error GoTo ErrorHandler

    Dim ManifestFileName As String
    Dim ManifestFilePathColons As String
    Dim ManifestFilePathSlashes As String
    Dim iListFileNum As Integer
    Dim ManifestPresentationName As String

    Dim FullPresentationPath As String

    ' name of file containing files to be inserted
    ManifestFileName = "MANIFEST.txt"

    ' use the path with colons to work with the MANIFEST.txt file
    ManifestFilePathColons = "Macintosh HD:Users:freejak:Google Drive:stirling:course-topics:auto-consolidate:"

      ' use the path with slashes to work with the ActivePresentation.Slides.InsertFromFile PPT method
    ManifestFilePathSlashes = "Macintosh HD/Users/freejak/Google Drive/stirling/course-topics/auto-consolidate/"

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

    iListFileNum = FreeFile()
    Open ManifestFilePathColons & ManifestFileName For Input As iListFileNum

    ' Process the list
    While Not EOF(iListFileNum)
        ' Get a line from the list file
        Line Input #iListFileNum, ManifestPresentationName

            'The following invocation works, and the seperator must be a slash
        Call ActivePresentation.Slides.InsertFromFile("Macintosh HD/Users/freejak/Google Drive/stirling/course-topics/auto-consolidate/topic-1/control-structures.pptm", _
              ActivePresentation.Slides.Count)

        FullPresentationPath = ManifestFilePathSlashes & ManifestPresentationName

        'This invocation fails, the same error occurs if I call passing "ManifestFilePathSlashes & ManifestPresentationName" without the quotes
        ' This fails whether the seperators are colons or slashes
        ' Call ActivePresentation.Slides.InsertFromFile(FullPresentationPath, ActivePresentation.Slides.Count)

    Wend

    Close #iListFileNum
    MsgBox "DONE!"

NormalExit:
    Exit Sub
1

1 Answers

0
votes

Not sure if this is relevant but you’ve got an extra “topic1” subfolder when you type the path out, vs the path written into the string variables.