Excel_newbie_85
New Member
- Joined
- Nov 30, 2011
- Messages
- 20
Hey All!!
I have found this code and wondered what I'm needing to do to;
1.condense and remove unnecessary code
2.replace parts to suit my system
My printer name is Haribo001
(code is basically making the ports variable by creating an array)
The Goal is to have a code set so that when the ports change for the printers, the VBA doesn't fail.
I hope someone can help!
The code is:
Function NetworkPrinter(ByVal myprinter As String)
On Error Resume Next
Dim
Dim X As Integer
'/// Define NetWork Array \\\
NetWork = Array("Ne00:", "Ne01:", "Ne02:", "Ne03:", "Ne04:", _
"Ne05:", "Ne06:", "Ne07:", "Ne08:", _
"Ne09:", "Ne10:", "Ne11:", "Ne12:", _
"Ne13:", "Ne14:", "Ne15:", "Ne16:", _
"LPT1:", "LPT2:", "File:", "SMC100:")
'Setup printer to Print
X = 0
TryAgain:
On Error Resume Next
'Printer
Application.ActivePrinter = myprinter & Prt_On & NetWork(X)
If Err.Number <> 0 And X < 16 Then
X = X + 1
GoTo TryAgain
ElseIf Err.Number <> 0 And X > 15 Then
GoTo PrtError
End If
On Error GoTo 0
NetworkPrinter = myprinter & Prt_On & NetWork(X)
errorExit:
Exit Function
PrtError:
'no printer found
NetworkPrinter = ""
Resume errorExit
End Function
I have found this code and wondered what I'm needing to do to;
1.condense and remove unnecessary code
2.replace parts to suit my system
My printer name is Haribo001
(code is basically making the ports variable by creating an array)
The Goal is to have a code set so that when the ports change for the printers, the VBA doesn't fail.
I hope someone can help!
The code is:
Function NetworkPrinter(ByVal myprinter As String)
On Error Resume Next
Dim
NetWork
As VariantDim X As Integer
'/// Define NetWork Array \\\
NetWork = Array("Ne00:", "Ne01:", "Ne02:", "Ne03:", "Ne04:", _
"Ne05:", "Ne06:", "Ne07:", "Ne08:", _
"Ne09:", "Ne10:", "Ne11:", "Ne12:", _
"Ne13:", "Ne14:", "Ne15:", "Ne16:", _
"LPT1:", "LPT2:", "File:", "SMC100:")
'Setup printer to Print
X = 0
TryAgain:
On Error Resume Next
'Printer
Application.ActivePrinter = myprinter & Prt_On & NetWork(X)
If Err.Number <> 0 And X < 16 Then
X = X + 1
GoTo TryAgain
ElseIf Err.Number <> 0 And X > 15 Then
GoTo PrtError
End If
On Error GoTo 0
NetworkPrinter = myprinter & Prt_On & NetWork(X)
errorExit:
Exit Function
PrtError:
'no printer found
NetworkPrinter = ""
Resume errorExit
End Function
Last edited: