mrnacar
Board Regular
- Joined
- Jan 27, 2010
- Messages
- 188
- Office Version
- 365
- Platform
- Windows
The following macro works fine except the port number is limited only to 9. So if I have 10 or more print devices, then the macro won't work if the device we're looking for is on port 10 or above. Is there a way to write it so that it will work up to maybe 15 devices?
Code:
Sub printform()
Dim WS As Worksheet
Set WS = ActiveSheet
Dim sCurrentPrinter As String
sCurrentPrinter = ActivePrinter
For i = 0 To 9
Err.Clear
On Error Resume Next
Application.ActivePrinter = "LGLDOUBLE on Ne0" & i & ":"
If Err.Number = 0 Then GoTo printnow
On Error GoTo 0
Next
On Error GoTo 0
Exit Sub
printnow:
Dim iCopies As String
iCopies = Application.InputBox("How many copies do you want to print?", Type:=2)
If iCopies <> vbNullString Then
WS.PrintOut Copies:=iCopies
Else
Exit Sub
End If
ActivePrinter = sCurrentPrinter
End Sub