ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Class Modules vs Modules (https://www.excelbanter.com/excel-programming/278193-class-modules-vs-modules.html)

Jeff Marshall

Class Modules vs Modules
 
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



Tom Ogilvy

Class Modules vs Modules
 
Although class modules aren't discussed extensively, this may provide what
you need to know:

From Chip Pearson's site:

http://www.cpearson.com/excel/codemods.htm
where to put your code

--
Regards,
Tom Ogilvy

Jeff Marshall wrote in message
...
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





Chip Pearson

Class Modules vs Modules
 
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.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Jeff Marshall" wrote in message
...
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






All times are GMT +1. The time now is 11:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com