A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
The ActivePrinter property returns an active printer name string just like below:
\naeajaxsps06v\JAX-BL919-FL2-RM69-HPCP4525PCL on Ne02:
From the above string, we can see that " on Ne02:" is added at the end of "\naeajaxsps06v\JAX-BL919-FL2-RM69-HPCP4525PCL".
Please use the following function to set your network printer name:
'#######################################################
'Returns the full network printer name.
'If you want the function to change the active printer,
'blnToChange must set to value of True.
'#######################################################
Function MatchFullNetworkPrinterName(ByVal strNetworkPrinterName As String, Optional ByVal blnToChange As Boolean = False) As String
Dim strCurrentPrinterName As String
Dim strTempPrinterName As String
Dim i As Long
strCurrentPrinterName = Application.ActivePrinter
i = 0
Do While i < 100
strTempPrinterName = strNetworkPrinterName & " on Ne" & Format(i, "00") & ":"
'/* Try to change to the network printer. */
On Error Resume Next
Application.ActivePrinter = strTempPrinterName
'/* Resets last exception-handler location to Nothing, disabling the exception. */
On Error GoTo 0
'/* If the network printer was found. */
If Application.ActivePrinter = strTempPrinterName Then
MatchFullNetworkPrinterName = strTempPrinterName
Exit Do
End If
i = i + 1
Loop
'/* Change back to the original printer. */
If Not blnToChange Then Application.ActivePrinter = strCurrentPrinterName
End Function
e.g
Sub Test()
Dim strPntName As String
strPntName = MatchFullNetworkPrinterName("\naeajaxsps06v\JAX-BL919-FL2-RM69-HPCP4525PCL", True)
If strPntName <> "" Then MsgBox "The active printer has been changed successfully!", vbOKOnly, "Tips"
End Sub
Have a great day!
Cristin Yan