Microsoft Office Tutorials and References
In Depth Information
When you read through the procedure, you’ll notice that there is no statement that sends any
value to any outside procedure. As mentioned in Chapter 4, the message box is used only to
send some output to the screen; no value is passed to any other procedures.
For more information on passing values between procedures, see “Passing Arguments to Procedures”
later in this chapter.
With the overview out of the way, it’s time to offer a more formal description of what consti
tutes a Sub procedure.
Private | Public ] [ Static ] Sub name [( arglist )] [
Exit Sub ]
Table 5-1 describes the elements of a Sub procedure.
Table 5-1. Elements of a Sub Procedure
An optional element that indicates the Sub procedure is accessible to all
other procedures in all modules. If used in a module that contains an
Option Private statement, the procedure is not available outside the
An optional element that indicates the Sub procedure is accessible only
to other procedures in the module where it is declared.
An optional element that indicates the Sub procedure’s local variables are
preserved between calls. The Static attribute doesn’t affect variables that
are declared outside the Sub procedure, even if they are used in the
A required element that indicates the name of the Sub (for example, Sub
AvailableCredit ). The name does need to follow the standard variable
An optional list of variables representing arguments that are passed to
the Sub procedure when it is called. Multiple variables are separated by
An optional group of statements to be executed within the Sub procedure.
To add a procedure to a code module, follow these steps:
Click Tools, Macro, Visual Basic Editor to display the Visual Basic Editor.
If necessary, click Insert, Module to create a new code module (or if you want to create
a new module for organizational purposes).