Selecting another network printer vba - Office 365

MyersEPS

New Member
Joined
Nov 2, 2018
Messages
14
Hello, everything that I can find on this is saying I have the correct code, but is still not working. I recorded the marco to select the printer, so I am assuming that is correct. Any help would be great. This is what I have;

Sub CHANGE_PRINTER_ONE()
Dim sCurrentPrinter As String
sCurrentPrinter = Application.ActivePrinter

Application.ActivePrinter = "\\IAN1516\Brother HL-2240 series LV Cell on Ne06:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"\\IAN1516\Brother HL-2240 series LV Cell on Ne06:", Collate:=True

Application.ActivePrinter = sCurrentPrinter
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
... just thinking about different options - to work around this, if you can't find a solution...

Would you be able to use the printer dialog call instead - to allow your users to select the required printer, during runtime?

Code:
application.Dialogs (xlDialogprint).Show
 
Upvote 0
Don't iterate printer ports, you can read it from the registry very easily:

Code:
Public Function GetPrinterPort(strPrinterName As String) As String
   Dim objReg As Object, strRegVal As String, strValue As String
   Const HKEY_CURRENT_USER = &H80000001
   Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
   strRegVal = "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\"
   objReg.getstringvalue HKEY_CURRENT_USER, strRegVal, strPrinterName, strValue
   GetPrinterPort = Split(strValue, ",")(1)
End Function
This post is 2 and a half years old but would just like to say a thank you as this has solved my issues and a very big headache!!!

I had it working originally with manually entering the Ne number alongside the printer name, however my Ne kept changing meaning I would have to manually change this everytime. The above works perfectly and makes it automatic again.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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