Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 906779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:26:43+00:00 2026-05-15T16:26:43+00:00

My current PowerShell script: $document = C:\\test.doc $word = new-object -comobject word.application $word.Visible =

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:26:44+00:00Added an answer on May 15, 2026 at 4:26 pm

    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

    Imports word = Microsoft.Office.Interop.Word
    Module Module1
        Sub Main()
            Dim args() As String = Environment.GetCommandLineArgs
            Dim path = args(1)
            Dim printer = args(2)
            Dim wordApp As word.Application = New word.Application
            wordApp.WordBasic.DisableAutoMacros(1)
            wordApp.Visible = False
            Dim doc As word.Document = wordApp.Documents.Open(path)
            wordApp.ActivePrinter = printer
            Dim background As Object = False
            doc.PrintOut(background)
            doc.Close(False)
            wordApp.WordBasic.DisableAutoMacros(0)
            wordApp.Quit()
        End Sub
    End Module
    

    Steps to recreate solution:

    1. Open VS2008 and create a new Console
      Application in VB.NET.
    2. Set a reference to Microsoft.Office.Interop.Word (version 11)
    3. Delete any code in Module1 and insert the code above.
    4. Save the project and name it "wordprinter". Build the project.
    5. Nav to the Release folder and grab the "wordprinter.exe" and put it anywhere you like. This will be your $wordprinterpath.
    6. Note the paths to your document and printer. This will be your $doc and $printer, respectively.
    7. Enter the following in PS:
            $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-Null

    You 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following powershell script: Get-ChildItem hkcu:\Test\Universe\Datawink\Switch1\Devices | ForEach-Object {Get-ItemProperty $_.pspath} I am able
I have the current powershell script $release = read-host enter release $fullPath = 10.0.0.3
current code (not working): /^script\s*type=\text\/javascript/i.test(tagName)
What's the best way to get the current PowerShell Cmdlet from another object? If
Current Application Server Configuration: IIS 6.0 Windows 2003 Server Standard Edition SP2 .NET Framework
I've written a Powershell script which will compare two databases and come up with
I have a Powershell script that reads values off of the pipeline: PARAM (
I have a PowerShell script that checks that a certain directory is on the
I'm trying to write a PowerShell script that will do the following: Executes a
I need a PowerShell script that can access a file's properties and discover the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.