Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a network printer in Excel

Status
Not open for further replies.

dhaywood

IS-IT--Management
Jun 25, 2002
51
GB
Hi,

I'm struggling to work out how to set the default printer to a specific network printer in an excel workbook.

I know the bulk of the path is

\\severname\printer

but the

on NE0?: part of the path

changes for each workstation depending on the number of network printers attached.

What I want to do is query all the network printers and then set the application default to the one that begins with the path above.

I hope this makes sense to someone.

Thanks

 
This may be appropriate for the VBA forum, but if I were doing it with VBScript, I'd look at the WSHNetwork Object and the EnumPrintersCollection Method. That should get you started.
 
Make this in VBA

ActivePrinter = "printer name without on NE0?:
 
TomThumbKP

OK, I now understand how to list the printers with EnumPrinters and that all seems to be going fine.

How do I set a specific printer as the applications default?

i.e. I will EnumPrinters to query the current network printers but I then one to set a specific one as the current default for printing.

Do I use Set Printers(x) and if so how do I relate that to my EnumPrinters? Or is there a different way of doing this??

Thanks

Lamber

I tried that but it didn't want to play without the NExx netwrok i.d. on the end. Although thnking about it if I know where it is in the EnumPrinters list I should be able to reference it that way.

Cheers
 
What I would do is to go through the list of printers in EnumPrinters. Identify the name of the printer that you want to set as default (I think you said that the printer will have a differenty name for different users). I'll let you figure out an algorithm that will give you the appropriate printer name for a given user. Then I would use this name with the SetDefaultPrinter method of the WshNetwork Object.
 
in a vbs file, put:

Set WshNetwork = WScript.CreateObject("WScript.Network")

Set Printers = WshNetwork.EnumPrinterConnections
For i = 0 to Printers.Count - 1 Step 2
WScript.Echo i,i+1,"",Printers.Item(i),Printers.Item(i+1)
Next

WshNetwork.SetDefaultPrinter Printers.Item(0)
Or
WshNetwork.SetDefaultPrinter Printers.Item(1) 'Is the same

I think, this help.
 
In Word+VBA
ActivePrinter = "printer name without on NE0?:"
this works, in excell+vba not.

I don't know why.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top