Note that there are some explanatory texts on larger screens.

plurals
  1. POPowerPoint 2007 SP2, ExportAsFixedFormat in PowerShell?
    text
    copied!<p>Yesterday I was trying to batch convert a group of PPTs into PDFs for a friend, and I decided to have a look at PowerShell, since it's been sitting on my HD for a while.</p> <p>Here's the code I've come up with.</p> <pre><code>$p = new-object -comobject powerpoint.application # I actually don't know why I have to set the window to visible, # but it doesn't work otherwise, anyway, it's not the real problem I have $p.visible = 1 $f = $p.presentations.open('\some\file.ppt') $f.ExportAsFixedFormat('\some\newfile.pdf', 2) </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/bb265637.aspx" rel="nofollow noreferrer" title="MSDN ref. page">2 is for PDF</a></p> <p>Since the "brute force" method didn't work ("type mismatch") I tried to import the enum type with</p> <pre><code>$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF $f.ExportAsFixedFormat('\some\newfile.pdf', $pptypepdf) </code></pre> <p>The strange thing here is that it still throws a "type mismatch" error...</p> <p>Also, SaveAs works fine with</p> <pre><code>$f.SaveAs('\some\newfile.pdf', 32) # 32 is for PDF </code></pre> <p>What am I doing wrong?</p> <p><strong>Update</strong></p> <p>Relevant documentation:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/bb265637.aspx" rel="nofollow noreferrer">PpFixedFormatType Enumeration</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/bb231096.aspx" rel="nofollow noreferrer">ExportAsFixedFormat Method</a></li> </ul> <p>Here's the full error message</p> <pre><code>$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF $f.ExportAsFixedFormat($filepath, $pptypepdf) Exception calling "ExportAsFixedFormat" with "2" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))" At line:1 char:23 + $f.ExportAsFixedFormat &lt;&lt;&lt;&lt; ($filepath, $pptypepdf) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ComMethodTargetInvocation </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload