MrTinkertrain
Board Regular
- Joined
- Feb 7, 2007
- Messages
- 66
- Office Version
- 365
- 2021
Hello gurus,
I have the following problem.
I have this piece of code to print some sheets on a network printer :
This code does the trick, but for some unknown reason that printer port (NE03: ) changes every now and then (??)
Yesterday I needed to set it to NE02: and today I had to set it to NE03: to make this code work.
In order to prevent this problem I would like to change that printer port dynamically.
I have been searching for a solution and I found a function which shows the network printing port :
Can someone help me out with the combination of those two snippets of code ?
I've been trying to solve it for a few hours, but I get stuck ...
Thanx in advance
Best regards,
Mike
I have the following problem.
I have this piece of code to print some sheets on a network printer :
Code:
Application.ScreenUpdating = False
Sheets("nadrukorder print").Visible = True
Sheets(Array("archiefmap", "nadrukorder print")).Select
Application.ActivePrinter = "HP LaserJet 3390 Series PCL 6 op Ne03:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("nadrukorder").Activate
Sheets("nadrukorder print").Visible = False
Application.ScreenUpdating = True
This code does the trick, but for some unknown reason that printer port (NE03: ) changes every now and then (??)
Yesterday I needed to set it to NE02: and today I had to set it to NE03: to make this code work.
In order to prevent this problem I would like to change that printer port dynamically.
I have been searching for a solution and I found a function which shows the network printing port :
Code:
Public Function GetPrinterPort2(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
GetPrinterPort2 = Mid$(strValue, 10, 5)
End Function
Can someone help me out with the combination of those two snippets of code ?
I've been trying to solve it for a few hours, but I get stuck ...
Thanx in advance
Best regards,
Mike