Exit Instruction
Syntax
Exit {All|Do|For|Function|Property|Sub|While}
Group
Description
The exit instruction causes the macro to continue without performing some or all of the remaining instructions.
Parameters
| Exit | Description |
|---|---|
| All | Exits all macros. |
| Do | Exits the Do loop. |
| For | Exits the For or For Each loop. |
| Function | Exits the Function block. This instruction clears Err and sets Error`$' to null. |
| Property | Exits the Property block. This instruction clears Err and sets Error`$' to null. |
| Sub | Exits the Sub block. This instruction clears Err and sets Error`$' to null. |
| While | Exits 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