Hi,
I have a Macro to update some DocVariables then for me to select which printer I wish to use from a list of 2.
I am using the procedure from an Excel Macro that I've set before, but it is not working in word.
My problem is that my Input Box is in a loop that I cannot leave unless I press CTRL+BREAK.
Please can you have a look at my Check Input section BOLD below...
Please note that I would like the input to be checked that it is a Number, and that the number is 1 or 2, and if Cancel is Clicked then Exit Macro.
Sub PrintCheckList()
'PrintOut Time Change Check List
'Settings
'Variables
Dim PlusMinus As String
Dim ChangeHour As String
Dim Default_Printer_Name As String
Dim MyPrinter As String
Dim Printer_Name As String
Dim Printer_Name1 As String
Dim Printer_Name2 As String
Dim Printer_Name0 As Variant
'Defaults
Default_Printer_Name = Application.ActivePrinter
Printer_Name1 = "Kodak ESP+7 on Ne01:"
Printer_Name2 = "HP Photosmart B110a Series on Ne02:"
PlusMinus = ""
ChangeHour = ""
'Set Change Details
If Month(Now()) = "3" Then
PlusMinus = "+"
ChangeHour = "1:00am"
Else
PlusMinus = "-"
ChangeHour = "2:00pm"
End If
'Update the Document
With ActiveDocument
.Variables("PlusMinus").Value = PlusMinus
.Variables("ChangeHour").Value = ChangeHour
End With
'Update all Field Codes
For Each FCRange In ActiveDocument.StoryRanges
For Each FCField In FCRange.Fields
FCField.Update
Next FCField
Next FCRange
Question:
'Question to Set the Printer to Use
Printer_Name0 = InputBox("Please select the Printer you wish to use..." + Chr(10) _
+ Chr(10) _
+ " Please enter the Number for the Printer..." + Chr(10) _
+ Chr(10) _
+ " 1. " + Left(Printer_Name1, Len(Printer_Name1) - 9) + "." + Chr(10) _
+ " 2. " + Left(Printer_Name2, Len(Printer_Name2) - 9) + "." + Chr(10) _
+ Chr(10) _
+ " The Current Printer is " + Chr(147) + Default_Printer_Name _
+ Chr(148) + "." + Chr(10) _
+ Chr(10), "Print Video Tickets...", 1)
'Check Input
If Printer_Name0 = vbCancel Then
Exit Sub
ElseIf Not IsNumeric(Printer_Name0) Or Printer_Name0 < 1 Or _
Printer_Name0 > 2 Then
GoTo Question
End If
'Goto Printer from your Selection
If Printer_Name0 = "1" Then
GoTo Printer1
ElseIf Printer_Name0 = "2" Then
GoTo Printer2
End If
Printer1:
Printer_Name = Printer_Name1
Application.ActivePrinter = Printer_Name
GoTo Print_Out
Printer2:
Printer_Name = Printer_Name2
Application.ActivePrinter = Printer_Name
Print_Out:
ActiveDocument.ActiveWindow.PrintOut _
Range:=wdPrintFromTo, _
From:="1", _
To:="1"
Cancel:
Application.ActivePrinter = Default_Printer_Name
End Sub
Thank you in advance,
Neil