How to open document that contains AutoOpen macro with powershell?

Posted by grom on Stack Overflow See other posts from Stack Overflow or by grom
Published on 2010-05-17T02:55:29Z Indexed on 2010/05/17 3:00 UTC
Read the original article Hit count: 290

Filed under:
|

My current powershell script:

$document = "C:\\test.doc"
$word = new-object -comobject word.application
$word.Visible = $false
$word.DisplayAlerts = "wdAlertsNone"
$word.AutomationSecurity = "msoAutomationSecurityForceDisable"
$doc = $word.Documents.Open($document)
$word.ActivePrinter = "\\http://ptr-server:631\pdf-printer"
$background = $false
$doc.PrintOut([ref]$background)
$doc.close([ref]$false)
$word.quit()

But it results in an alert box "The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros."

How can I open the document without it running the AutoOpen macro or displaying any sort of dialog prompt?

© Stack Overflow or respective owner

Related posts about powershell

Related posts about word