Programming Reference Manual
 
Syntax
 
Exit {All|Do|For|Function|Property|Sub|While}
 
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 or 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.
See Also
 
Example
 
Sub Main
L$ = InputBox$("Enter <span style='color: #004080; font-weight: bold;'>Do</span>, <span style='color: #004080; font-weight: bold;'>For</span>, <span style='color: #004080; font-weight: bold;'>While</span>, <span style='color: #0000FF; font-weight: bold;'>Sub</span> 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 "<span style='color: #004080; font-weight: bold;'>Do</span> was entered"
 
For I = 1 To 10
If L$ = "FOR" Then Exit For
Next I
If I = 1 Then Debug.Print "<span style='color: #004080; font-weight: bold;'>For</span> was entered"
 
I = 10
While I > 0
If L$ = "WHILE" Then Exit While
I = I-1
Wend
If I = 10 Then Debug.Print "<span style='color: #004080; font-weight: bold;'>While</span> was entered"
 
If L$ = "SUB" Then Exit Sub
Debug.Print "<span style='color: #0000FF; font-weight: bold;'>Sub</span> was not entered."
If L$ = "ALL" Then Exit All
Debug.Print "All was not entered."
End Sub