Page 121 - Excel Progamming Weekend Crash Course
P. 121
h540629 ch07.qxd 9/2/03 9:33 AM Page 96
96 Saturday Morning
REVIEW
Sub and function procedures provide the basic structure for organizing your VBA code. An
Excel program consists of at least one procedure, and more complex programs contain many
procedures. Among the items covered in this session are:
A procedure is an independent section of code that has been assigned a name and
can be called (executed) from other code.
Function procedures return a value to the calling program; sub procedures do not.
A procedure can accept arguments that are used to pass data to the procedure. Each
argument has a specific, assigned data type.
You can place essentially any VBA code in a procedure. The main exceptions are
other procedure definitions, user-defined type definitions, and enumeration
definitions.
By default a procedure’s scope is public, making the procedure available to all modules
in all projects.
QUIZ YOURSELF
1. What is the main difference between a sub procedure and a function procedure?
(See the “Function Procedures” section.)
2. How many arguments can a procedure take? (See the “Procedure Arguments”
section.)
3. Do you need to enclose the arguments in parentheses when calling a sub procedure?
(See the “Calling Procedures” section.)
4. What happens if you pass an argument to a procedure that has a different data
type than the argument was declared to be? (See the “Argument Type Checking”
section.)
5. How do you define an optional procedure argument with a default value? (See the
“Optional Arguments” section.)
6. What is the default scope of a procedure? (See the “Procedure Scope” section.)