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?
Environment Details:
- Word 2003 SP3
- Windows Server 2003 R2 – Standard Edition – Service Pack 2
- Powershell Version 1.0
Turns out this is MUCH easier to do in VB.NET than in C# (which I never could figure out). But all you would need to do is create, say, a console application with a single routine. Here are the instructions:
Code
Steps to recreate solution:
Application in VB.NET.
Module1and insert the code above.$wordprinterpath.$docand$printer, respectively.$wordprinterpath = "C:\\path\\wordprinter.exe" $doc ="""C:\\Users\\me\\Documents\\Your doc.doc""" $printer = "\\http://ptr-server:631\pdf-printer" Invoke-Expression "$wordprinterpath $doc $printer" | out-NullYou should be good to go after this. I haven’t tested the printing part of this, so that may need some work, but disabling of the auto-macros and opening the doc works.