![]() |
selecting a printer within a macro
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 |
selecting a printer within a macro
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/comm...xp=&sloc=en-us "OlieH" wrote: 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 |
selecting a printer within a macro
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. "JMB" wrote: 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/comm...xp=&sloc=en-us "OlieH" wrote: 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 |
selecting a printer within a macro
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 "OlieH" wrote: 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. "JMB" wrote: 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/comm...xp=&sloc=en-us "OlieH" wrote: 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 |
selecting a printer within a macro
JMB wrote:
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 -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200706/1 |
selecting a printer within a macro
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" wrote: JMB wrote: 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 -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200706/1 |
selecting a printer within a macro
JMB wrote:
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. -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200706/1 |
All times are GMT +1. The time now is 08:13 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com