Select a network Printer

Jat999

New Member
Joined
May 7, 2016
Messages
49
Hi all

I have written a macro to generate pallet labels. These labels need to be printed on specific printers as they will have self adhesive labels in the tray. The IT dept. have created these printers on the network with a specific naming of "Barcode" in the description of the printer.

As part of the user form, the user selects one of the three possible printers available. The assumption is that the user will have the printer installed but not necessarily the default printer.

The age-old problem I have encountered is around the network number (NExx) will be different for each PC the macro is run from, so therefore cannot be hard-coded into the printer string.

The question for me, is it possible using xlDialogPrinterSetup list to find the relevant printer from the list and set this as being the active printer.

I would like the code to compare the hard-coded name in the macro to compare with the xlDialogPrinterSetup list and find the correct printer.

I do not want the user to have to select the printer each time as this would be time consuming.

I know there have been a lot of posts around this, but i am struggling to find a suitable solution.

Thanks in advance
 
Hi
I'm trying to use this to work around the Ne## change issue, but I'm running into the following issues:
1. The second "Dim curNePrint As String" is marked as a duplicate, and holds up the code. If I remove it then
2. The code prints to the wrong printer. I suspect this is because Leo_Prn isn't true so it skips down to the print line and just prints. I tried changing it to Leo_Prn = False, but then nothing happens (and I did change the printer name to match mine)*. What is this Leo_Prn, and what can I use since I don't have a form with a tick box?

My end game is to set a pair of macros as buttons, one to print to each printer.

*I got the name of the printer using the following code (which I got from a thread on here somewhere, but I've lost it), and just knocked the numbers off the end of the Ne
VBA Code:
Sub test()
MsgBox Application.ActivePrinter
End Sub
Leo_prn in my example was a hard coded checkbox field on the user form. The code was reduced subset of a larger code.
so in the above, for simplicity, I am verifying if the value returned is true. If you have multiple printers then you need a loop to determine which printer to select
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi

Leo_prn in my example was a hard coded checkbox field on the user form. The code was reduced subset of a larger code.
so in the above, for simplicity, I am verifying if the value returned is true. If you have multiple printers then you need a loop to determine which printer to select
Thank you for responding!

Gotcha. The two printers I need for the buttons are named by adding on to the previous printer name*, so is there a way to tell it, if the printer name is "(md) on Ne" then (and finish off with the code above)?

If I can't have parenthesis in the code like above, or get it to differentiate between the similar names, I can rename the printers again. That was the easy part.

*the one had (md) added to the end, and the other is Saven Yellow (but there's still a Saven on the computer, and it has to stay). If I need to, I'll just rename the first red and the latter yellow.

Also, I won't be able to test code until Monday.
 
Upvote 0
Thank you for responding!

Gotcha. The two printers I need for the buttons are named by adding on to the previous printer name*, so is there a way to tell it, if the printer name is "(md) on Ne" then (and finish off with the code above)?

If I can't have parenthesis in the code like above, or get it to differentiate between the similar names, I can rename the printers again. That was the easy part.

*the one had (md) added to the end, and the other is Saven Yellow (but there's still a Saven on the computer, and it has to stay). If I need to, I'll just rename the first red and the latter yellow.

Also, I won't be able to test code until Monday.
Hi

I am sorry, but I will not be able to respond until later next week as I am leading a big ERP go-live project this week so working silly hours.
 
Upvote 0
Hi

I am sorry, but I will not be able to respond until later next week as I am leading a big ERP go-live project this week so working silly hours.
I understand. I hope the hours have become less silly.
 
Upvote 0
I appear to have solved my issue.

This is the code I'm using (cobbled together from various sources, "Yellow" is the name of my printer)

VBA Code:
Sub yellow()
'
'

'

For i = 0 To 10
On Error Resume Next
Application.ActivePrinter = "Yellow on Ne" & Format$(i, "00") & ":"
'exit if we succeed
If Err.Number = 0 Then Exit For
Next i

If Not Application.ActivePrinter Like "Yellow*" Then
MsgBox "Unable to set the printer", vbCritical
Exit Sub
End If

sCurrentPrinter = Application.ActivePrinter
Application.ActivePrinter = MyPrinter
ActiveSheet.PrintOut '
Application.ActivePrinter = sCurrentPrinter


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,699
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top