Class Modules vs Modules

J

Jeff Marshall

Hi ,

Can someone please explain in laymen's terms the difference between the two?

The advantage of a class module over a module ?

Is there any special requirements that a class module needs over a module?

Thanks for your help.
Jeff
 
C

Chip Pearson

Jeff,

The short answer is that if you have to ask the difference between modules
and class modules, don't use class modules. Put all your code in standard
modules.

The longer answer is that you use class modules to create your own objects.
Objects are defined by their properties, methods, and events -- all of which
are placed in the class module -- and then defined in to existence with the
Set New syntax. If you are familiar with Type variables (called Structures
or Structs in other programming languages), you can think of a class as a
"Type With Code". You use Property Let/Get/Set statements to define the
properties (variables) of the class, and then add code with Subs and
Functions. Once you've defined all the properties and methods in the class
module, you create an object variable (or "instance") of that class with
code like

Dim X As Class1
Set X = New Class1

A full discussion of how (and when) to use classes is beyond the scope of a
newsgroup post. A good book on VBA should provide at least the basics.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top