KK99
KK99

Reputation: 1989

Merging multiple powerpoint slides into one and maintain single point of source?

We have some set of (powerpoint) pptx files which are targeted for different audiences

I was thinking of merging different slide sets based on target audiance

I want to know if it's possible to

Is this possible graphically or by a VBA?

Ex:

Set 1 (Dev.pptx):

Set 2 (Manager.pptx)

Set 3 (all.pptx)

If i change any one of the Pptx (A,b,c,d,e) the combined files should be updated automatically

Upvotes: 1

Views: 1986

Answers (2)

Borislav Markov
Borislav Markov

Reputation: 1725

This is possible with VBS on a Windows with installed PowerPoint.exe.

Create a script named merge.vbs with this content:

Option Explicit

Sub WriteLine ( strLine )
    WScript.Stdout.WriteLine strLine
End Sub

Sub WriteError ( strLine )
    WScript.Stderr.WriteLine strLine
End Sub

Dim inputFile1
Dim inputFile2
Dim outputFile
Dim objPPT
Dim objFso
Dim objPresentation

If WScript.Arguments.Count <> 3 Then
    WriteError "You need to specify 2 input files and one output file."
    WScript.Quit 1
End If

inputFile1 = WScript.Arguments(0)
inputFile2 = WScript.Arguments(1)
outputFile = WScript.Arguments(2)

Set objFso = CreateObject("Scripting.FileSystemObject")

If Not objFso.FileExists( inputFile1 ) Then
    WriteError "Unable to find your input file " & inputFile1
    WScript.Quit 1
End If
If Not objFso.FileExists( inputFile2 ) Then
    WriteError "Unable to find your input file " & inputFile2
    WScript.Quit 1
End If

WriteLine "Input File 1 :  " & inputFile1
WriteLine "Input File 2 :  " & inputFile2
WriteLine "Output File: " & outputFile

Set objPPT = CreateObject( "PowerPoint.Application" )

' Open presentation with window hidden
Set objPresentation = objPPT.Presentations.Open(inputFile1, True, False, False)

mergeAndKeepSourceFormatting objPresentation, inputFile2

' Reference for this at https://learn.microsoft.com/en-us/office/vba/api/powerpoint.presentation.saveas
WriteLine "Saving File: " & outputFile
objPresentation.SaveAs outputFile

objPresentation.Close
ObjPPT.Quit

'
' Add the file to the loaded presentation
'
Sub mergeAndKeepSourceFormatting(ByRef objPresentation, ByVal newPptxFile)
    WriteLine "Merging file: " & newPptxFile
    Dim newSlides
    Dim oldSlides
    oldSlides = objPresentation.Slides.Count
    newSlides = objPresentation.Slides.InsertFromFile( newPptxFile, objPresentation.Slides.Count)
    objPresentation.Slides.Range(FillRangeArray(oldSlides + 1, oldSlides + newSlides)).ApplyTemplate newPptxFile

End Sub


Function FillRangeArray(n1, n2) 
    Dim myArr()
    Redim myArr(n2 - n1)
    Dim i
    For i = 0 to (n2 - n1)
        myArr(i) = n1 + i
    Next
    FillRangeArray = myArr
End Function

Then from the command line you can call it:

CSCRIPT merge.vbs "A.pptx" "B.pptx" "resultA_B.pptx"

Please adjust the script to your needs or call it several times to merge the resulting file with the next one.

Upvotes: 1

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

The simplest and probably most reliable solution would be to put all of the slides into one file and then create custom shows, one for each target audience.

Another approach would be to have a main "menu" presentation, one slide with links to sub-presentations, one per audience. Each of those presentations would have its own "menu" slide that links to A.pptx, B.pptx etc. as needed.

At the end of A.pptx, add an End Presentation link; click on that (or just press ESC to quit the presentation) and you'll be returned to the sub-menu presentation.

Upvotes: 1

Related Questions