Merge PowerPoint files Using PowerShell and PowerPoint application object

1k Views Asked by At

I need a simple PowerShell script to merge n number of pptx files into a single pptx file. Seems like MergeWithBaseline off the presentation object should work, but I continue to get an error.

Add-type -AssemblyName office add-type -assembly microsoft.office.interop.powerpoint

$strwithPresentation = ".\one.pptx" $strbaselinePresentation = ".\two.pptx"

$Application = New-Object -ComObject powerpoint.application

$presentation = $application.Presentations.add()

$presentation.MergeWithBaseline($strwithPresentation, $presentation.FullName)

I have tried many options but continue to get this error:

PS C:\Users\ltsharpe\Documents\scripts> C:\Users\ltsharpe\Documents\scripts\MergePPTX.ps1 Error HRESULT E_FAIL has been returned from a call to a COM component. At C:\Users\ltsharpe\Documents\scripts\MergePPTX.ps1:10 char:1

  • $presentation.MergeWithBaseline($strwithPresentation, $presentation.F ...
  •   + CategoryInfo          : OperationStopped: (:) [], COMException
      + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
    
    

What is the best way to programmatically merge pptx files into a single one? Few hits on searches and most are 10+ years old. Any suggestions are greatly appreciated as I do not want to cut/paste 20+ pptx files into one on a monthly basis :(.

0

There are 0 best solutions below