selecting a printer within a macro

G

Guest

I wish to select a printer from within a macro. I have the printer name but
since it is a network printer the channel changes from machine to machine.
Can you index through all available printer and select the one you want.

All help is greatly appreciated.
OlieH
 
G

Guest

One approach:
strActiveprinter = ActivePrinter 'Capture current printer
Application.Dialogs(xlDialogPrinterSetup).Show
.....
....
activeprinter = stractiveprinter 'Reset the printer


If you want to try to set the printer programmatically, you'll likely need
an API function to return an array of the printers installed on the machine,
then loop through those to find the one you want.

Tom Ogilvy posted some info on this:

http://www.microsoft.com/office/com...5298&catlist=&dglist=&ptlist=&exp=&sloc=en-us
 
G

Guest

JMB; does such a function exists? I think this is what I am needing. I am
currently using the .show command and make the operator select the correct
one and then recheck to make sure they do so.
 
G

Guest

Hmm.. that link I posted did not work. Actually, I misspoke, although you
can use API to return an array of printers, you can also use WScript (which
is what the link to Tom's post was supposed to show you). Here is code
previously posted by Norman Jones that uses the same method:

Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub
 
F

Francois via OfficeKB.com

JMB said:
Hmm.. that link I posted did not work. Actually, I misspoke, although you
can use API to return an array of printers, you can also use WScript (which
is what the link to Tom's post was supposed to show you). Here is code
previously posted by Norman Jones that uses the same method:

Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")


Depending how many network computors you have, something like this might help.
..


If computername = "UKWD3577" Then Application.ActivePrinter = "HP Officejet
Pro K550 Series on Ne00:"
If computername = "UKWD3636" Then Application.ActivePrinter = "\\
UKWD3577\HP Officejet Pro K550 Series on Ne01:"
If computername = "UKWD3567" Then Application.ActivePrinter = "\\
UKWD3577\HP Officejet Pro K550 Series on Ne02:"
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub
JMB; does such a function exists? I think this is what I am needing. I am
currently using the .show command and make the operator select the correct
[quoted text clipped - 21 lines]
 
G

Guest

One downside could be if the computer names change (the office gets new
machines) and the code needs to be changed to reflect the new machine names.


Francois via OfficeKB.com said:
JMB said:
Hmm.. that link I posted did not work. Actually, I misspoke, although you
can use API to return an array of printers, you can also use WScript (which
is what the link to Tom's post was supposed to show you). Here is code
previously posted by Norman Jones that uses the same method:

Sub ListPrinters()
Dim wshNetwork As Object
Dim oDrives As Object
Dim oPrinters As Object
Dim iCount As Integer
Dim sCurrentprinter As String
sCurrentprinter = Application.ActivePrinter
Set wshNetwork = CreateObject("WScript.Network")


Depending how many network computors you have, something like this might help.
..


If computername = "UKWD3577" Then Application.ActivePrinter = "HP Officejet
Pro K550 Series on Ne00:"
If computername = "UKWD3636" Then Application.ActivePrinter = "\\
UKWD3577\HP Officejet Pro K550 Series on Ne01:"
If computername = "UKWD3567" Then Application.ActivePrinter = "\\
UKWD3577\HP Officejet Pro K550 Series on Ne02:"
Set oDrives = wshNetwork.EnumNetworkDrives
Set oPrinters = wshNetwork.EnumPrinterConnections
For iCount = 0 To oPrinters.Count - 1 Step 2
Debug.Print oPrinters.Item(iCount + 1)
Next
End Sub
JMB; does such a function exists? I think this is what I am needing. I am
currently using the .show command and make the operator select the correct
[quoted text clipped - 21 lines]
All help is greatly appreciated.
OlieH
 
F

Francois via OfficeKB.com

JMB said:
One downside could be if the computer names change (the office gets new
machines) and the code needs to be changed to reflect the new machine names.
Hmm.. that link I posted did not work. Actually, I misspoke, although you
can use API to return an array of printers, you can also use WScript (which [quoted text clipped - 31 lines]
All help is greatly appreciated.
OlieH


Indeed that is a problem that I've come across... I am on to my third PC, and
other users have changed as well.
 

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

Top