Understanding Named Arguments and Optional Arguments
When you call a Sub or Function procedure, you can supply arguments positionally, in the order they appear in the procedure's definition, or you can supply the arguments by name without regard to position.
For example, the following Sub procedure takes three arguments:
You can call this procedure by supplying its arguments in the correct position, each delimited by a comma, as shown in the following example:
You can also call this procedure by supplying named arguments, delimiting each with a comma.
A named argument consists of an argument name followed by a colon and an equal sign (:=), followed by the argument value.
Named arguments are especially useful when you are calling a procedure that has optional arguments. If you use named arguments, you don't have to include commas to denote missing positional arguments. Using named arguments makes it easier to keep track of which arguments you passed and which you omitted.
Optional arguments are preceded by the Optional keyword in the procedure definition. You can also specify a default value for the optional argument in the procedure definition. For example:
When you call a procedure with an optional argument, you can choose whether or not to specify the optional argument. If you don't specify the optional argument, the default value, if any, is used. If no default value is specified, the argument is it would be for any variable of the specified type.
The following procedure includes two optional arguments, the
You can call this procedure using named arguments as shown in the following examples.