Chapter 7. bsing Class Modules to Create.Objects
Class modules are used to create objects. There are many reasons for you as a developer to create your own objects, including the following:
•To encapsulate VBA and Windows API code to make it transportable and easy to use and reuse, as shown in Chapter 9 Understandinw and Uaing Windows API Calls •To trap events •To raise events •To create your own objects and object models In this chapter we assume you are already familiar with writing VBA code to manipulate the objects in Excel and are familiar with the Excel object model that defines the relationships among those objects. We also assume you are familiar with object properties, methods and events. If you have written code in the ThisWorkbook module, any of the modules behind worksheets or charts or the module associated with a userform, you have already worked with class modules. One of the key features of these modules, like all class modules, is the ability to trap and respond to events.
The goal of this chapter is to show you how to create your own objects. We begin by explaining how to create a single custom object and then show how you can create a collection containing multiple instances of the object. We continue with a demonstration of how to trap and raise events within your classes.
|