I am trying to add error prevention to my macro.
Sub DebugMacro()
'
' DebugMacro Macro
' Macro recorded 11/7/2009 by
'
Dim NumberofUniqueStencils As Integer
Dim StencilMaterial(14) As String
Dim StencilQuantity(14) As Variant
Dim NumberofStencilLines() As Variant
Dim CharactersPerLine(9) As Variant
Dim CharacterHeight(9) As Variant
Dim SymbolQuantity(9) As Variant
Dim SymbolWidth(9) As Variant
Dim GraphicWidth(9) As Variant
Dim SymbolHeight(9) As Variant
Dim TextLineSpacing(8) As Variant
Dim Default As Integer
On Error GoTo Canceled:
prompt = "How many unique stencils is the customer ordering?"
Caption = "Customer Order Information"
Default = 1
NumberofUniqueStencils = Application.InputBox(prompt, Caption, Default, Type:=1)
If NumberofUniqueStencils = 0 Then
Exit Sub
End If
For x = 1 To NumberofUniqueStencils
On Error GoTo Canceled:
prompt = "Input the material to be used for unique stencil number " & x & " ('OB', 'Mylar' or 'Mag')"
Caption = "Customer Order Information"
StencilMaterial(x) = Application.InputBox(prompt, Caption, Type:=2)
On Error GoTo Canceled:
prompt = "Input the customer order quantity for unique stencil number " & x
Caption = "Customer Order Information"
Default = 1
StencilQuantity(x) = (Application.InputBox(prompt, Caption, Default, Type:=1))
If StencilQuantity(x) = 0 Then
Exit Sub
End If
On Error GoTo Canceled:
prompt = "How many text lines will unique stencil number " & x & " have?"
Caption = "Customer Order Information"
Default = 1
ReDim NumberofStencilLines(Val(Application.InputBox(prompt, Caption, Default, Type:=1)) - 1)
Next x
Canceled: Exit Sub
'
End Sub
In all dialog box prompts for user input, if a character is input when the a numberic is requested or the user selects the Cancel button, the macro exits.
This works just as intended. However, for the code in red, if the user inputs a numeric instead of a character, the type:=2 critieria is ignored, the macro accepts the input (when it should not), and moves on to the next dialog box. Additionally, if the user selects the Cancel button, the macro moves on to the next dialog box instead of exiting. What additional code is needed to prevent the macro from proceeding to the next dialog box?
Bookmarks