none
PowerPoint error using ExportAsFixedFormat2 function in PowerShell RRS feed

  • Question

  • Hi expert,

    Apologize if this is not the right place for this question.

    I am writing some PowerShell script to export a pptx file to pdf, below is part of my code,

    Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint
    $Powerpoint = New-Object -ComObject Powerpoint.Application
    $Presentation = $Powerpoint.Presentations.Open($templateFilePath, [Microsoft.Office.Core.MsoTriState]::msoTrue, [Microsoft.Office.Core.MsoTriState]::msoTrue)


    $intent = [Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent]::ppFixedFormatIntentPrint
    $Presentation.ExportAsFixedFormat2($filePathPdf, [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::ppFixedFormatTypePDF, $intent)

    But I receive below error in ExportAsFixedFormat2() function, 

    Exception setting "ExportAsFixedFormat2": Cannot convert the "ppFixedFormatIntentPrint" value of type "PpFixedFormatIntent" to type "Object".
    At C:\Users\ps\Merge-PowerPointPresentation.ps1:232 char:13
    +             $NewPresentation.ExportAsFixedFormat2($filePathPdf, [Micr ...
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : RuntimeException

    How to make it work?

    Thanks,

    Michael

    Friday, April 24, 2020 5:43 AM