Lesson 24Class Modules

Class modules—the very name has caused many a burgeoning Excel VBA programmer to turn toward other areas of VBA study. For some reason, the use of class modules is not a skill held by many otherwise knowledgeable VBA programmers, despite the power and flexibility class modules can provide to your workbook projects.

Class modules are not rocket science, but they are a different kind of VBA animal that takes some extra attention to grasp. I want to express three objectives in this lesson:

  • Explain what classes and class modules are.
  • Describe what class modules can do for you.
  • Provide examples of class modules applied to UserForm and embedded worksheet controls.

Here is an opportunity for you to set yourself apart from the VBA crowd and learn a valuable skill that has actually been available in Excel since Office 97. Though you won't need class modules for most of your projects, this lesson helps you recognize when the time is right to use class modules, and most importantly, how to program them.

What Is a Class?

A class is the formalized definition of an object that you create. Your first reaction might be to wonder why you'd ever need to create yet another object in Excel, which seemingly has no shortage of objects. Actually, you normally don't need to, but there will be times when your workbook will be better off if you do.

A new class (as in classification) is like a blueprint for your created object and its properties, methods, and events. In Lesson ...

Get Excel VBA 24-Hour Trainer, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.