Exit Instruction
Syntax:
Exit {All|Do|For|Function|Property|Sub|While}
Group:
Flow Control
Description:
The exit instruction causes the macro to continue
with out doing some or all of the remaining instructions.
Exit
Description
All Exit all macros.
Do Exit the Do
loop.
For Exit the For
of For Each loop.
Function Exit the Function
block. Note: This instruction clears the Err
and sets Error$ to null.
Property Exit the Property
block. Note: This instruction clears the Err
and sets Error$ to null.
Sub Exit the Sub
block. Note: This instruction clears the Err
and sets Error$ to null.
While Exit the While
loop.
Example:
Sub Main
L$ = InputBox$("Enter Do,
For, While, Sub
or All:")
Debug.Print "Before DoSub"
DoSub UCase$(L$)
Debug.Print "After DoSub"
End Sub
Sub DoSub(L$)
Do
If L$ = "DO" Then Exit Do
I = I+1
Loop While I < 10
If I = 0 Then Debug.Print
"Do was entered"
For I = 1 To 10
If L$ = "FOR" Then Exit For
Next I
If I = 1 Then Debug.Print
"For was entered"
I = 10
While I > 0
If L$ = "WHILE" Then Exit While
I = I-1
Wend
If I = 10 Then Debug.Print
"While was entered"
If L$ = "SUB" Then Exit Sub
Debug.Print "Sub
was not entered."
If L$ = "ALL" Then Exit All
Debug.Print "All was not entered."
End Sub