Getting the Printer Port
Do you know how windows appends that "on Ne01" to your ActivePrinter. In the old days we had to loop through all the possible digits to find which one didn't error out. Well no more!
Holger uses the registry to find the printer port. Very clever. However, if you have back slashes in your regestry key name, the scripting shell object won't work for retrieving them. To the shell, back slashes are path separators, so it's trying to navigate down some path that doesn't exist.
To overcome that problem, you can use Registration Manipulation Classes.

If your you're a late binding kind of a guy, use CreateObject("RegObj.Registry") in your code. With this dll, we can loop through all of the keys in a folder, like so:
Dim objReg As RegObj.Registry
Dim objRootKey As RegObj.RegKey
Dim sKey As String
Dim objVal As RegObj.RegValue
Dim sData As String
Dim vData As Variant
sKey = "\HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices\"
Set objReg = New RegObj.Registry
Set objRootKey = objReg.RegKeyFromString(sKey)
For Each objVal In objRootKey.Values
If objVal.Name = sPrinterName Then
sData = objVal.Value
Exit For
End If
Next objVal
If Len(sData)> 0 Then
vData = Split(sData, ",")
GetPrinterPort = vData(UBound(vData))
Else
GetPrinterPort = ""
End If
Set objReg = Nothing
End Function
I haven't tested that extensively, so use caution.


