NAMING ARGUMENTS TO METHODS

Many methods in VBA have arguments that let you specify options for the action to be performed. If the Wag method of the Tail object of our mythical robodog has arguments (for example, WagRate, the number of wags per second; WagTime, the duration of wagging in seconds; and WagArc, the number of degrees of arc in each wag), you can specify them using either of two syntaxes.

In the first syntax, which is often called the by-name syntax, you name each argument you use, in any order. For example, this statement wags the tail three times per second for an hour, over an arc of 180 degrees:

Robodogs("Fido").Tail.Wag _
WagRate := 3, _
WagTime := 3600, _
WagArc := 180
You assign a value to an argument by using a colon and an equal sign, and you separate arguments with commas.

Note: The underscore character at the end of the first three lines tells VBA that the following line is part of the same statement. Using this symbol makes the list of supplied arguments easier to read. The underscore must always be preceded by a space character.

In the second syntax, which is often called the by-position syntax, you enter arguments in a prescribed order. For example, the preceding statement expressed in the by-position syntax looks like this:
Robodogs("Fido").Tail.Wag(3,3600,180)
Notice that the list of arguments is surrounded by parentheses. The by-position syntax isn’t as easy to read as the by-name syntax because you have to remember the order of arguments, and when you review the code at a later date, you won’t have the argument names to refresh your memory about their settings.

Note: Excel’s macro recorder records arguments by position rather than by name, which can make it more difficult to understand recorded macros than manually created macros in which you’ve named the arguments. Similarly, when you select a VBA keyword and press the F1 key, the VBE displays a Help topic describing the by-position syntax for the keyword.