Setting ActivePrinter in Excel

J

john Hoffman

Hello,

I am using automation in C# with an Excel spreadsheet.
All is well until I try to print to a printer other than
the default one. I use a C# print dialog to return me the
printer name to print to such as:

\\myserver\HP LaserJet 5Si MX

Using an Excel Macro as an example the macro yields:
Application.ActivePrinter = "\\eme_server\HP LaserJet
5Si MX on Ne01:"

ActiveWindow.SelectedSheets.PrintOut Copies:=1,
ActivePrinter:= _
"\\eme_server\HP LaserJet 5Si MX on Ne01:",
Collate:=True


Where can I find the port information i.e. "on Ne01"??
If I leave it off, Excel hangs!!

TIA,

John Hoffman
 
W

Wei-Dong Xu [MSFT]

Hi john,

Thank you for posting in MSDN managed newsgroup!

Excel needs the port to print. I write one sample code for you which will return the string for the excel print. You can choose the printer from the
dialog box and print your ActiveWorkbook.
'Code begin
Const xlDialogPrinterSetup = 9

Dim strOld as string
Dim strNew as string

strOld = Application.ActivePrinter
Application.Dialogs(xlDialogPrinterSetup).Show
'retrieve the printer customer specified
strNew = Application.ActivePrinter

'Print the ActiveworkBook
Application.ActiveWorkbook.PrintOut

'Restore the old printer
Application.ActivePrinter = strOld

'Code end

Please feel free to let me know if you have any further questions.

Does this answer your question? Thank you for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

John Hoffman

Hello Wei-Dong,

Thank-you for your help.

Actually, the way I wish to do it is to present a Print
Dialog box:
oSheet.Application.Dialogs[
Excel.XlBuiltInDialog.xlDialogPrint ].Show( opt,
opt.... );

My question is there are 30 possible parameters for the
show method. Where can I find some info on these???

Thanks!

John Hoffman


-----Original Message-----
Hi john,

Thank you for posting in MSDN managed newsgroup!

Excel needs the port to print. I write one sample code
for you which will return the string for the excel print.
You can choose the printer from the
 
W

Wei-Dong Xu [MSFT]

Hi John,

Thank you for replying!

The 30 optional parameters are prepared for all the excel built-in dialog box. You can find all the excel built-in dialog box from the excel Visaul Basic
Reference with the searching phrase "Built-In Dialog Box Argument Lists"(without quotation). You will find the help documentation "Built-In Dialog Box
Argument Lists" in the search result.

For the xlDialogPrint dialog box, the definition is as below:
Dialog box constant Argument list(s)
-------------------- -----------------
xlDialogPrint range_num, from, to, copies, draft, preview, print_what,
color, feed, quality, y_resolution, selection, printer_text,
print_to_file, collate

There are 16 arguments in the argument list for xlDialogPrint. This means xlDialogPrint built-in dialog box only uses 15 parameters of Show methods.
Then you can specify the value accroding to the scenario for each arguments.

Furthermore, you can also check the the VBA reference documentation for Excel 2002 Built-in dialog box from Microsoft.com. Please go to:
Built-In Dialog Box Argument Lists
http://msdn.microsoft.com/library/d...ry/en-us/vbaxl10/html/xlmscDialogArgLists.asp

Please feel free to let me know if you have any further questions.

Does this answer your question? Thank you for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Similar Threads

Printer Names on a Network 5
Printing 2
Printing Problems 1
Network printing 2
VBA to print Word Document 1
Problem with printing from VB-script in Excel 2
Printing PDF from Excel 3
Need VBA help 3

Top