how do I use nprint (in DOS) to print Excel files?


Posted by Darrell Hahn on August 25, 1999 8:25 AM

I am writing a macro that (hopefully) will print a shared Excel file to a specific printer, regardless of where the user is. This proves to be difficult, since printers are set up differently on individual machines, making it impossible to set ActivePrinter=whatever. So I'm trying to use "nprint" in DOS, where I can just type the name of the printer. But when I print an excel file using nprint, I lose all colors/formatting/etc. Does anyone know of a way to tell nprint that this is an excel file and should print accordingly?

Posted by Chris on August 25, 1999 12:34 PM

If the printer is a network printer, why would it have different names on different machines? Setting the ActivePrinter property should work just fine.

Chris

Posted by Darrell on August 25, 1999 1:53 PM

When Joe sets up the printer on his machine, he calls it "The printer by the elevator." When Sarah sets up the printer on her machine, she calls it "The printer near the exit." Both are the same printer, but they have different names. In order to use ActivePrinter=, you'd have to use either ActivePrinter = "The printer by the elevator on \\server\printer," or ActivePrinter = "The printer near the exit on \\server\printer." But I would like to write a macro where the document would be printed to the same printer, regardless of which machine is being used.

Posted by Chris on September 01, 1999 5:55 AM

Darrell,

I'm sorry that I don't have a very good answer for you. I'm not familiar with any API calls to get a list of installed printers. My idea was that if you had a list of the installed printers you could search the text for the part of the name that was always the same. The only thing I can think of, and I sure you won't want to do it, is to use the SendKeys command to select a printer from the print dialog. Then check the string using ActivePrinter.Name. Then if that isn't the right printer, you would go through the process again. See what I mean about not liking this answer.

Our IS folks don't let the users change the LAN printer names, now I know why.

Chris

Posted by Darrell on September 03, 1999 10:49 AM

Hi Chris - Thanks for putting some more thought in to it. Yeah, I was thinking, too, that it would be pretty easy to search through a list of available printers and choose the correct one by choosing the string that contained the correct printer. Alas, I'm not sure how to get a list of installed printers! I tried using SendKeys to do exactly what you said, to go to the Print Dialog and choose a printer, but I couldn't even get it to choose ANY printer, much less a specific printer. Thanks again.

Posted by Chris on September 08, 1999 6:25 AM

If you really want to give the SendKeys a shot, here's the code to pick the first printer on the list:

Sub asdf()
Application.SendKeys "^p"
Application.SendKeys "%m"
Application.SendKeys "{HOME}"
Application.SendKeys "~"
Application.SendKeys "{ESC}"
End Sub

If you wanted the second printer on the list, you would add this line after sending the HOME key:

Application.SendKeys "{DOWN}"

Good Luck!

Chris



Posted by Ivan Moala on September 09, 1999 2:35 AM


Darrell,
The above routine will work fine, just don't
test it from your VBE !! as the sendkeys
works on the Active Application which would be
your VBE, you could get undersirable effects!
So using sendkeys can manipulate the VBA editor
if you really wanted to.


Good luck

Ivan