473,659 Members | 2,662 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.Act ivePrinter = "\\eme_server\H P LaserJet
5Si MX on Ne01:"

ActiveWindow.Se lectedSheets.Pr intOut Copies:=1,
ActivePrinter:= _
"\\eme_server\H P 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 17958
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 xlDialogPrinter Setup = 9

Dim strOld as string
Dim strNew as string

strOld = Application.Act ivePrinter
Application.Dia logs(xlDialogPr interSetup).Sho w
'retrieve the printer customer specified
strNew = Application.Act ivePrinter

'Print the ActiveworkBook
Application.Act iveWorkbook.Pri ntOut

'Restore the old printer
Application.Act ivePrinter = 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.Applicat ion.Dialogs[
Excel.XlBuiltIn Dialog.xlDialog Print ].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 xlDialogPrinter Setup = 9

Dim strOld as string
Dim strNew as string

strOld = Application.Act ivePrinter
Application.Di alogs(xlDialogP rinterSetup).Sh ow
'retrieve the printer customer specified
strNew = Application.Act ivePrinter

'Print the ActiveworkBook
Application.Ac tiveWorkbook.Pr intOut

'Restore the old printer
Application.Ac tivePrinter = 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
10589
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 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...
7
1951
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 one of the cells should contain a multiline text? I already tried by inserting a <br> inside the <td>. But this won't work. -- Michael G. Schneider
7
2283
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 works great. Testing it through my web service failed ! Looking in the pdf printer, I can see no sheets have been selected despite the fact I did it in the macro.
0
1813
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 isn't responding in the time specified by the OLE/DDE timeout setting" appears. No error appears in Excel. Any help ?
0
1602
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 being converted to a number field. For example one value in a string field is "0008" and when I export into excel it turns into 8. I know when I manually import a csv file into excel I have to option to say what type of field a specific column...
9
4541
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 TypeOf obj Is IDisposable Then DirectCast(obj, IDisposable).Dispose()
3
20836
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 spreadsheets. I've used this software in previous positions and was very comfortable with the software but I'm a bit of a novice in setting up databases. However,I learn quickly. I am looking for something like an Access database template that I can...
27
109378
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 function. If I am in debug mode and have a breakpoint at this line, I can see when hovering my mouse over "Range("C1").Value" the actual value in that cell (in my case 30), but when I want to step to the next statement, the VB programs ends (due to some...
0
1577
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 I exprort to excel it's changed to Unicode UTF-8 so all of the characters had lost, text cannot be display correctly. Is it possible to add a charset setting to code. Thank you!
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6178
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.