Word Automation - Print to Specified Printer

  • Thread starter Thread starter Stephen Barrett
  • Start date Start date
S

Stephen Barrett

Hi all,

I am having issues with the age old problem that Word changes the default
printer for the system when you set ActivePrinter to something.

I am doing Word Automation in a Windows service running under a specific
account. I can pretty much do everything I need to do. This includes
opening a merge document and merging with a separate datafile. Turning
merge off to make document a normal document, and print. The problem I am
having is that the printer I specify becomes the default printer for the
system, which causes other apps on server to work improperly.

I have heard rumors that there is a VBA way of printing without changing the
default printer, but I need to be able to pass the printer name to use into
the routine. The printer is actually a PDF generation print driver that is
given to me on the fly through a separate programable object. I am getting
strange results because both Word and the PDF generation software changes
the "default" printer to print. In a multiuser environment, this is causing
me some headaches.

Help.
 
Stephen,

Instead of using the automation model to print the document, I would
recommend calling ShellExecuteEx through the P/Invoke layer, executing the
"PrintTo" verb. It will allow you to specify the printer to print the
document to and should not change the default printer (hopefully).

Hope this helps.
 
Wouldn't this popup a dialog? This has to be fully automated with no user
input (works server side).

Nicholas Paldino said:
Stephen,

Instead of using the automation model to print the document, I would
recommend calling ShellExecuteEx through the P/Invoke layer, executing the
"PrintTo" verb. It will allow you to specify the printer to print the
document to and should not change the default printer (hopefully).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Stephen Barrett said:
Hi all,

I am having issues with the age old problem that Word changes the default
printer for the system when you set ActivePrinter to something.

I am doing Word Automation in a Windows service running under a specific
account. I can pretty much do everything I need to do. This includes
opening a merge document and merging with a separate datafile. Turning
merge off to make document a normal document, and print. The problem I am
having is that the printer I specify becomes the default printer for the
system, which causes other apps on server to work improperly.

I have heard rumors that there is a VBA way of printing without changing the
default printer, but I need to be able to pass the printer name to use into
the routine. The printer is actually a PDF generation print driver that is
given to me on the fly through a separate programable object. I am getting
strange results because both Word and the PDF generation software changes
the "default" printer to print. In a multiuser environment, this is causing
me some headaches.

Help.
 
Well I found out from Microsoft that the only way to do this was to use late
binding in combination with WordBasic. Since VB.NET makes this a lot easier
since it handles pluggin in missing parms, I decided to write a wrapper in
VB.NET to do what I need.
 
Back
Top