473,505 Members | 15,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting ActivePrinter in Excel

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


Nov 15 '05 #1
3 17917
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.
Nov 15 '05 #2
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 thedialog 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.

.

Nov 15 '05 #3
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/de...ogArgLists.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.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
10574
by: Stephen Barrett | last post by:
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...
7
1948
by: Michael G. Schneider | last post by:
From ASP I create response, which is to be shown as an Excel worksheet in the user's browser (by setting the ContentType and creating a table). This works fine. Does anybody know what to do, if...
7
2261
by: Franck | last post by:
Hi, I'm using an xls file through my web service to print out a pdf file from which I returned path. In this way, got a macro in my XLS file which do the print out. Testing it from the xls file...
0
1806
by: CLarkou | last post by:
I have a program in Access 2003. I use DDE commands for sending data to excel and setting up the page setup. on 2 machines the error "error 286: the other application in the DDE conversation...
0
1581
by: Jerry | last post by:
I have an application that is trying to export multiple datasets to and excel workbook in different worksheets. I have gotten the export to work except for string fields that happen to be numbers...
9
4518
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
3
20826
by: lsmith | last post by:
Dear group, I am the new volunteer coordinator for a non-profit organization in Tucson, AZ. One of my main focuses is to develop our own volunteer pool using either MS Access 2002 or Excel...
27
109350
by: geniet | last post by:
Hello all of you, I have some problem in setting cells values (or fromat or...) in my Excel spreadsheet using a VB statement like within my Module: Range("C1").Value = 20 I have this in a...
0
1561
VietPP
by: VietPP | last post by:
Hi all, I've asked too much question in this day, hehe. I'm trying to export my table data in OracleDB to excel. The problem is my charset in database is US7ACSII (using Vietnamese font), when...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.