Skip to Main Content
Excel 2003 VBA Programmer's Reference
book

Excel 2003 VBA Programmer's Reference

by Paul T. Kimmel, Stephen Bullen, John Green, Rob Bovey, Robert Rosenberg
July 2004
Beginner content levelBeginner
1176 pages
27h 45m
English
Wrox
Content preview from Excel 2003 VBA Programmer's Reference

6

Class Modules

Class modules are used in VBA to create your own customized classes. Here are some examples of problems for which you might use a custom class modules:

  • Respond to application events; you can write code that is executed whenever any open workbook is saved or printed, for example
  • Respond to embedded chart events
  • Set up a single event procedure that can be used by a number of ActiveX controls such as text boxes in a UserForm
  • Encapsulate Windows API methods to permit interaction with Windows
  • Encapsulate standard VBA procedures in a form that is easy to transport into other workbooks

In this chapter, we will define some class to get the idea of how class modules work. Then, we will apply the principles to some more useful examples. You are already familiar with Excel's built-in objects, such as the Worksheet object, and you know that objects often belong to collections such as the Worksheets collection. You also know that objects have properties and methods, such as the Name property and the Copy method of the Worksheet object.

Using a class module, you can create your own “blueprint” for a new object, such as an Employee class. You can define properties and methods for the class, such as a Rate property that records the employee's current rate of pay, and a ChangeTitle that implicitly affects other aspects of the Employee's data. You can also create a new collection for the object, such as the Employees collection. The class module is a plan for the objects you want ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel 2007 VBA Programming with XML and ASP

Excel 2007 VBA Programming with XML and ASP

Julitta Korol
Microsoft® Office Excel 2003 Programming Inside Out

Microsoft® Office Excel 2003 Programming Inside Out

Curtis Frye, Wayne S. Freeze, Felicia K. Buckingham
Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
Access™ 2007 VBA Programmer's Reference

Access™ 2007 VBA Programmer's Reference

Teresa Hennig, Rob Cooper, Geoffrey Griffith, Armen Stein

Publisher Resources

ISBN: 9780764556609Purchase book