Sub

This statement declares the name, parameters, and code that form the body of a Sub procedure.

Syntax

[Public | Private] Sub name [(arglist)]
[statements]
[Exit Sub]
[statements]
End Sub

Parameters

name
Name of the Sub; follows standard variable naming conventions.
arglist
List of variables that represent parameters passed to the Sub procedure when it is called. Commas separate multiple variables.

The arglist parameter has the following syntax and parts:

[ByVal | ByVal] varname[()]

ByVal
Indicates that the parameter is passed by value.
ByRef
Indicates that the parameter is passed by reference.
varname
Name of the variable that represents the parameter; follows standard variable naming conventions.
statements
Any group of statements to be executed within the body of the Sub procedure.

Remarks

If you do not explicitly specify Private, Sub procedures are public by default, that is, they are visible to all other procedures in your module.

The Exit Sub statement causes an immediate exit from a Sub procedure.