Changing Active printer Problem in Excel

G

Galin Iliev

Hello folks,
I am using MS Word and Excel automating to perform some specific tasks.
For these needs I have to print Document and Workbook on specific system
printer.
there is no problem with MS Word documents as I change it with this code:
oWordApp.WordBasic.FilePrintSetup Printer:=sNEWPrinter,
DoNotSetAsSysDefault:=1

Unfotunately, I found there is no such alternative in MS Excel so I have
tested these ways (in VB6 and MS Excel 2002):
oExcelApp.ActivePrinter = "IBM Graphics"
and
oExcelApp.ActivePrinter = "IBM Graphics on PRN1:"
and
oExcelApp.ActiveWorkbook.ActiveSheet.Printout activeprinter:="IBM Graphics
on PRN1:"
and
oExcelApp.ActiveWorkbook.ActiveSheet.Printout activeprinter:="IBM Graphics"

but all of them returned "Application-defined or object-defined error"
or more specific: "Method 'Active printer' of object'_ Application failed
error" in MS Excel 2002 VBA

I am able to change system default printer using WIN API but this is not
desirable as users could use my program as background and start printing job
by other applciation.

Thank you in advance

Galin Iliev
MCSD
Software Consulting Services
 
A

Andrew Cushen

Galin-

This Knowledge Base article "appears" to address your
problem:
http://support.microsoft.com/default.aspx?scid=kb;en-
us;211801

But I tried the suggestions and cannot get it to work.
Maybe you will have more luck.

According to the article, the error you mentioned is
caused by not spelling the name of the printer exactly as
it appears in the Printers dialog.

If the article doesn't help, I suggest you save the name
of the current default printer, use the Win32 API to
change the printer immediately before you print, then
change it back immediately after printing finishes. That
should eliminate problems with other programs printing.

HTH,

-Andrew
======================================================
 
G

Galin Iliev

This didn't work to me too.
I made all article's suggestions but they did not work too.

Thank you for the advise.
obviosly this is hard question.

Galin Iliev
MCSD
 

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