views:

332

answers:

2

Hi SO,

I'm looking for a way to print a Word document programmatically with VBA in an Outlook macro. I think there may be two ways to accomplish this:

1) Use the Shell to print the document via command line switch with Word.

2) Use Outlook the print the document.

Is there a way to do this? I need to be able to specify the printer.

Thanks!!

A: 

I think you should be able to use word object to invoke the printing functionality programatically. I know we did use excel classes programatically, so I am guessing you should be able to do word as well.

DevByDefault
I generally program in a Linux environment. Can you post some sample code or link to an article about invoking Word objects? Thanks so much!
Tyler
A: 

Ok. After some Google-ing, this is how it's done:

Dim WordObject As Object
Dim DocumentObject As Object

Set WordObject = CreateObject("Word.Application")
WordObject.Visible = True //Specifies if you want the actual window to appear

Set DocumentObject = WordObject.Documents.Open("File Name Here")
WordObject.ActivePrinter = "Printer Name Here"
WordObject.PrintOut (True) //Set to True to print in the background

Sources: http://msdn.microsoft.com/en-us/library/bb213458.aspx

Tyler