Word Automation - Setting ActivePrinter changes System Default

  • Thread starter Stephen Barrett
  • Start date
S

Stephen Barrett

I am doing word automation with Word 2003. Everything works great except
for one thing. When I set the word object's ActivePrinter to a different
printer, it changes the system default. I looked for help on MS site and
they say it is a known issue. The work around is to use WordBasic commands
like as follows.

------------------------------------
MORE INFORMATION
To select a new printer without having Word change the default system
printer, use the WordBasic FilePrintSetup method with the
DoNotSetAsSysDefault flag set to True. For example, instead of using the
following code:
Set oWord = CreateObject("Word.Application")
oWord.ActivePrinter = "HP LaserJet 4 on LPT2"

Use the following:
Set oWord = CreateObject("Word.Application")
oWord.WordBasic.FilePrintSetup Printer:="HP LaserJet 4 on LPT2", _
DoNotSetAsSysDefault:=1
------------------------------------------------

The problem I have is that this is VB script to be used in ASP or VB6. In
C#, the Word.Application.WordBasic property returns back a generic object.
I don't see any objects available that I can cast the object to to simulate
what MS suggests. Is there some kind of secret way to do this in .Net?

I thought about grabbing the default printer before I set the ActivePrinter,
then setting the saved value back to ActivePrinter after I print. I would
prefer to do it the proper way, but I can find the objects to do it.

Help?

SB
 
M

MarkAAinsworth

Try the following:

With Dialogs(wdDialogFilePrintSetup)
.Printer = strPrinter ' strPrinter is the name of the printer
(instead of setting ActivePrinter)
.DoNotSetAsSysDefault = True ' Doesn't change the system default
printer
.Execute ' Carries out the changes using the FilePrintSetup dialog
but without displaying it
End With

I haven't got Word 2003 to test this, but I hope you have success with
it.

MA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top