Excel Automation - Changing Printers

C

Carl Wolter

Hello,

I am using VB .Net 2003 to automate Excel and Word as
part of a larger project I am working on. I need to give
users the option of printing to different network
printers. I have a PrintDialog box that stores the current
user choices in PrintDocument1. Before I start to printout
the Excel and Word files I have the following code..

objword.ActivePrinter=
PrintDocument1.PrinterSettings.PrinterName

objexcel.ActivePrinter =
PrintDocument1.PrinterSettings.PrinterName

The Word automation will print correctly to the user
defined printer.

The Excel line however returns
An unhandled exception of
type 'System.Runtime.InteropServices.COMException'

Any ideas?

Carl Wolter
 
C

Carl Wolter

-----Original Message-----
Hello,

I am using VB .Net 2003 to automate Excel and Word as
part of a larger project I am working on. I need to give
users the option of printing to different network
printers. I have a PrintDialog box that stores the current
user choices in PrintDocument1. Before I start to printout
the Excel and Word files I have the following code..

objword.ActivePrinter=
PrintDocument1.PrinterSettings.PrinterName

objexcel.ActivePrinter =
PrintDocument1.PrinterSettings.PrinterName

The Word automation will print correctly to the user
defined printer.

The Excel line however returns
An unhandled exception of
type 'System.Runtime.InteropServices.COMException'

Any ideas?

Carl Wolter

I managed to get this to work correctly just taking a
slightly different route. You can overload the
object.printout method. One of the optional parameters is
the activeprinter name. I was able to use
Printdocument1.Printersettings.PrinterName there to set
the active printer.

Now for my question, why can I directly assign it with
the Word Object Model and not with Excel?


Carl
 

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