Microsoft Office Tutorials and References
In Depth Information
What Is a Class Module?
It’s easy to get lost on any new topic if the emphasis on learning it is based
on definitions and theory. That is why most of this lesson relies on real-world
examples to show what class modules are all about. Though kept to a minimum,
the definitions and theory in this lesson are useful for you to gain a perspective
on class modules. If you don’t fully comprehend all definitions the first time
around, don’t worry — the VBA examples will be your biggest ally in helping
you understand the process of developing class modules.
A new class (as in classification) is like a blueprint for your created object and its properties,
methods, and events. In Lesson 16 you learned about User Defined Functions; where class modules are
concerned, you can think of a class as a user-defined model for an object that you create. You’ll see
examples later in the lesson that will help clarify the theory.
WHAT is A clAss ModulE?
A class module is a special module in the Visual Basic Editor whose purpose is to hold VBA code
that defines classes. A class module looks like any other kind of module you have seen, and in its
own way acts like one, too. For example, whereas the code for worksheet event procedures goes
into worksheet modules, the code for creating and defining classes goes into class modules.
You create a class module in the VBE by clicking Insert Class Module from the menu bar as
shown in Figure 21-1. A class module is created with the default name of Class1 as shown in
Figure 21-2.
figurE 21-1
 
Search JabSto ::




Custom Search