PowerPoint ExportAsFixedFormat in Powershell

I am trying to use ExportAsFixedFormat

in PowerPoint 2007 from a PowerShell 2.0 script. Only the first two arguments are required, but that won't work.

I always get:

Exception causing "ExportAsFixedFormat" with "2" argument (s): "Mismatch type. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"

I read that all arguments must be specified for it to work, but that doesn't work either. BTW, the same method works for me in Word 2007 and Excel 2007.

So what's wrong with that:

Add-type -AssemblyName Office
Add-type -AssemblyName Microsoft.Office.Interop.PowerPoint

$p = new-object -comobject powerpoint.application 
$p.visible = 1  
$document = $p.presentations.open('somefile.ppt')


$document.ExportAsFixedFormat($Path, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::ppFixedFormatTypePDF, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent]::ppFixedFormatIntentScreen, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
[Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder]::ppPrintHandoutVerticalFirst, 
[Microsoft.Office.Interop.PowerPoint.PpPrintOutputType]::ppPrintOutputSlides, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
$null, 
[Microsoft.Office.Interop.PowerPoint.PpPrintRangeType]::ppPrintAll, 
[System.Reflection.Missing]::Value, 
$true, 
$true, 
$true, 
$true, 
$false, 
[System.Reflection.Missing]::Value)

      

0


a source to share


2 answers


I realize this is a late answer, but I think I have a solution. (I tried to call this method in C # using NetOffice and get the same error)

It looks like there is a bug in Microsoft Powerpoint (at least in versions 2007 and 2010). The PrintRange parameter must be specified as the default (0) is invalid!

So a working script might look like this:



Add-type -AssemblyName Office
Add-type -AssemblyName Microsoft.Office.Interop.PowerPoint

$p = new-object -comobject powerpoint.application 
$p.visible = 1  
$document = $p.presentations.open('somefile.ppt')
$ranges = $document.PrintOptions.Ranges
$range = $ranges.Add(1,1)


$document.ExportAsFixedFormat($Path, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::ppFixedFormatTypePDF, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent]::ppFixedFormatIntentScreen, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
[Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder]::ppPrintHandoutVerticalFirst, 
[Microsoft.Office.Interop.PowerPoint.PpPrintOutputType]::ppPrintOutputSlides, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
$range, 
[Microsoft.Office.Interop.PowerPoint.PpPrintRangeType]::ppPrintAll, 
[System.Reflection.Missing]::Value, 
$true, 
$true, 
$true, 
$true, 
$false, 
[System.Reflection.Missing]::Value)

      

Note that the $ range parameter has now been passed.

NB - This answer is adapted from the solution here: https://netoffice.codeplex.com/discussions/449288

+1


a source


Change $null

to [System.Reflection.Missing]::Value

.



0


a source







All Articles