To print to a network Printer you need to first get the full network printer name and after that you can get a print for the worksheet.
Code:
Sub PrintToNetworkPrinterExample()
Dim strCurrentPrinter As String, strNetworkPrinter As String
strNetworkPrinter = GetFullNetworkPrinterName("HP LaserJet 8100 Series PCL")
If Len(strNetworkPrinter) > 0 Then ' found the network printer
strCurrentPrinter = Application.ActivePrinter
'Change to the network printer
Application.ActivePrinter = strNetworkPrinter
Worksheets(1).PrintOut print something
' Change back to the previously active printer
Application.ActivePrinter = strCurrentPrinter
End If
End Sub
Function GetFullNetworkPrinterName(strNetworkPrinterName As String) As String
Dim strCurrentPrinterName As String, strTempPrinterName As String, i As Long
strCurrentPrinterName = Application.ActivePrinter
i = 0
Do While i < 100
strTempPrinterName = strNetworkPrinterName & " on Ne" & Format(i, "00") & ":"
On Error Resume Next 'Try to change to the network printer
Application.ActivePrinter = strTempPrinterName
On Error GoTo 0
If Application.ActivePrinter = strTempPrinterName Then
'The network printer was found
GetFullNetworkPrinterName = strTempPrinterName
i = 100 makes the loop end
End If
i = i + 1
Loop
'Remove the line below if you want the function to change the active printer
End Function
Bookmarks