Jump to content
Sign in to follow this  

Hot to automate printing a word document to prn file.

Recommended Posts


I'm new with AutoIt.
I want to automate the process of printing a Microsoft word file to prn file.

What I have:

1.A Printer installed ($PrinterName) port to FILE:
2. Code I used:
 _Word_DocPrint ( $oDoc, 1, 1, -1, 1, $PrinterName, 0)
 ;($b_Background = 1 in order to continue)
 ;After call Word_DocPrint, MS Word will show "Print to file" window, and ask file name.
 WinWaitActive("Print to file")

 ControlSetText ( "Print to file", "", "ID:1001", "C:TempNEW-FILE.prn", 0 )

;ID:1001 is text edit box 

ControlClick( "Print to file", "", "[CLASS:Button; TEXT:OK; INSTANCE:7]")

When I run these in debug mode, it paused at _Word_DocPrint, not even continue run other lines.

Then I tried with another DOS command line to print:

Dim $cmd = 'winword.exe Default.doc /mFilePrintDefault'
Run ($cmd)
Opt("WinTitleMatchMode", 2)
WinWait ("Print to file", "", 2)
ControlCommand ( "Print to file", "", "ID:1001", "GetSelected", "" )
ControlSetText ( "Print to file", "", "ID:1001", "C:TempNEW-FILE.prn", 0 )
WinWaitActive("[CLASS:Button; TEXT:OK; INSTANCE:7]")
ControlClick( "Print to file", "", "[CLASS:Button; TEXT:OK; INSTANCE:7]")

Although it goes to every command lines to the end, but it doesn't save any file and 'ok' quit the dialog window.

Something wrong in my code.

Any suggestions please....


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.