End Statement

Description

Ends a procedure or block.

Syntax

EndEnd Function End IfEnd Property End SelectEnd SubEnd TypeEnd With

The End statement syntax has these forms:

Statement Description
End Terminates execution. Never required by itself but may be placed anywhere in a procedure to close files opened with the Open statement and to clear variables.
End Function Required to end a Function statement.
End If Required to end a block If...Then...Else statement.


Statement Description
End Property Required to end a Property Let, Property Get, or Property Set procedure.
End Select Required to end a Select Case statement.
End Sub Required to end a Sub statement.
End Type Required to end a user-defined type definition (Type statement).
End With Required to end a With statement.


Remarks

When executed, the End statement resets all module-level variables and all static local variables in all modules. If you need to preserve the value of these variables, use the Stop Statement instead. You can then resume execution while preserving the value of those variables.

See Also

Exit Statement, Function Statement, If...Then...Else Statement, Property Get Statement, Property Let Statement, Property Set Statement, Select Case Statement, Stop Statement, Sub Statement, Type Statement, With Statement.

Example

This example uses the End Statement to end code execution if the user enters an invalid password.


Sub Form_Load
    PassWord = "Swordfish"
    Pword = InputBox("Type in your password")
    If Pword <> PassWord Then
        MsgBox "Sorry, incorrect password"
        End
    End IfSub