This statement declares the name, parameters, and code that form the body of a Function procedure.
[Public | Private] Function name [(arglist)]
[statements]
[name = expression]
[Exit Function]
[statements]
[name = expression]
End Function
The arglist parameter has the following syntax and parts:
[ByVal | ByRef] varname[( )]
Public indicates that the Function procedure is accessible to all other procedures in all modules. Private indicates that the Function procedure is accessible only to other procedures in the module where it is declared. If not explicitly specified using either Public or Private, Function procedures are public by default; that is, they are visible to all other procedures in your module.
Function procedures can be recursive; in other words, they can call themselves to perform a specified task. However, recursion can lead to stack overflow.
To return a value from a function, assign the value to the function name. A function that returns an object reference returns Nothing if no object reference is assigned to name (using Set) within the Function.