Defining a Procedure

The syntax for defining a procedure is quite similar for both sub- and function procedures. For a sub procedure, the basic syntax is as follows:

Sub subname(argumentlist)
...
' Code goes here
...
End Sub

Subname is the name of the sub procedure, following the same VBA-naming rules that you learned in Chapter 5. The name must be unique within the project (with some exceptions when a procedure has private scope, as explained later in this chapter). The argumentlist specifies arguments (data) that are passed to the procedure. The details of passing arguments will be explained also. A procedure can take no arguments, in which case the name should be followed by an empty set of parentheses.

The syntax for defining a function ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.