Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is a clasmodule?

23 views
Skip to first unread message

Helge Klungland

unread,
Oct 8, 2001, 6:30:04 AM10/8/01
to
What do I use clasmodule for? Are there any links on internet/or books where
I can read more about it?

Helge (Oslo - Norway)


Nick Hodge

unread,
Oct 8, 2001, 3:19:57 PM10/8/01
to
Helge

As the MS server is a little slow tonight I will attempt an answer to this.

XL provides standard modules, where you write subs and functions which will
be used generally in your code.

Class modules are provided for two purposes.

1) To write code specific to XL objects. For example, those associated with
Worksheets, Workbooks, ChartSheets, etc, provided by MS
2) To design your own 'classes' of objects, with properties, events, etc of
their own, not provided as standard. E.g. Application Events, Embedded
Charts, etc.

I suspect Chip Pearson will have something on his site about these,
(www.cpearson.com), check under COM Add-Ins or Class Modules. I know he's a
bit of a 'whizz' on these.

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_...@lineone.net


"Helge Klungland" <helge.k...@nsb.no> wrote in message
news:Nefw7.12275$tu6.2...@news1.oke.nextra.no...

Ber Visser

unread,
Oct 8, 2001, 4:10:47 PM10/8/01
to

"Helge Klungland" <helge.k...@nsb.no> schreef in bericht
news:Nefw7.12275$tu6.2...@news1.oke.nextra.no...

Here is a very good tutorial:
http://www.microsoft.com/officedev/articles/movs109.htm
--
Ber Visser
Belgium

David Hager

unread,
Oct 8, 2001, 4:44:04 PM10/8/01
to
See Developers Tips in:

http://www.j-walk.com/ss/excel/eee/eee019.txt

--
David Hager
Excel MVP
Baton Rouge, La.

Helge Klungland wrote in message ...

Dave Peterson

unread,
Oct 8, 2001, 6:07:11 PM10/8/01
to
You could try http://groups.google.com/advanced_group_search

There was a very nice thread a few months ago.


http://groups.google.com/groups?hl=en&threadm=uxLOHiDw%24GA.196%40cppssbbsa02.microsoft.com&rnum=1

All on one line.

I did a search on "what is a class module" with *excel* as the newsgroup and
(Chip) Pearson as the author and a few popped up.

this link was the first.

--

Dave Peterson
ec3...@msn.com

Chip Pearson

unread,
Oct 8, 2001, 6:22:40 PM10/8/01
to
Helge,

A Class Module might be described as a "template" for an object. That probably
doesn't help much, so let's begin with an example. Suppose you are writing an
application used to keep track of employees. You would create a class module
named CEmployee. This would contain properties and methods related to an
employee. Indeed, a class is really defined entirely by its properties and
employees. Properties are the things that describe the class. For example,
your CEmployee class you have properties like Name, Address, PhoneNumber,
Department, IDNumber, and so on. These are the "adjectives" of the class.
Methods can be thought of as the "verbs". These are the procedures that do
things with the class. For example, your CEmployee class might have methods
like SendMail, PrintPaycheck, and so on. These are actions that are take on
that particular employee.

The Class Module doesn't describe any particular employee. It describes a
generic employee. This is an important thing to remember -- a class doesn't
refer to any employee in particular, it is only a 'blueprint' for any generic
employee. It is up to your code to create specific "objects" or specific
"employees" based on that general blueprint. Your code creates an "object"
based on the class module, also called an "instance" of the class, to identify a
specific employee. For example, you might have code like

Dim OneEmployee As CEmployee
Set OneEmployee = New CEmployee
OneEmployee.Name = "Helge Klugland"
OneEmployee.Address = "123 Oak Street"
OneEmployee.PhoneNumber = "(123) 456-7890"
OneEmployee.PrintPayCheck

Here, you're created a new object named "OneEmployee", based on the CEmployee
class, and assigned it some property values and then printed the pay check for
that employee.

This only begins to scratch the surface of what you can do with class modules.
There is so much more. Indeed, the entire Excel and the entire Windows system
is really based on classes. For more information, you should consult a book
like John Walkenbach's "Power Programming For Excel 2002" or John Green &
Stephen Bullen's "VBA Programmer's Reference". These have in-depth explanations
of what Class Modules are all about.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com


"Helge Klungland" <helge.k...@nsb.no> wrote in message
news:Nefw7.12275$tu6.2...@news1.oke.nextra.no...

pds

unread,
Oct 8, 2001, 8:41:15 PM10/8/01
to
"Helge Klungland" <helge.k...@nsb.no> wrote in message news:<Nefw7.12275$tu6.2...@news1.oke.nextra.no>...
> What do I use clasmodule for? Are there any links on internet/or books where
> I can read more about it?
>
> Helge (Oslo - Norway)

Helge,

Class modules are for creating your own objects.
An object have properties and methods that store local data
(properties) and perform operations (methods) on the object.
Once you've created your class you then create instances of the class
in the form of objects.

eg.

Create a class with the following code, and name it CPerson :

Option Explicit

Private msFirstName As String
Private mlAgeInYears As Long
Private msLastName As String

Public Property Let LastName(psLastName As String)
msLastName = psLastName
End Property

Public Property Get LastName() As String
LastName = msLastName
End Property

Public Property Let AgeInYears(plAgeInYears As Long)
mlAgeInYears = plAgeInYears
End Property

Public Property Get AgeInYears() As Long
AgeInYears = mlAgeInYears
End Property

Public Property Let FirstName(psFirstName As String)
msFirstName = psFirstName
End Property

Public Property Get FirstName() As String
FirstName = msFirstName
End Property

Public Sub ShowDetails()
Msgbox Me.FirstName & " " & ME.LastName & " is " &
CStr(Me.AgeInYears) & " years old!"
End Sub


Then add a module with the folloing code:

Sub Test()

Dim oPerson = New CPerson

With oPerson
.FirstName = "Steve"
.LastName = "Smith"
.AgeInYears = 30
.ShowDetails
End With

End Sub

Regards

Graham

--------------
Progressive Data Solutions
http://www.pdsolutions.com.au
Home of VB Code Cutter - VB/VBA Code Library & Dev Tool with Free code
formatting/indenting

David J. Braden

unread,
Oct 9, 2001, 6:34:18 PM10/9/01
to
Nice job, Chip. With all due respect to J-Walk, his book is poor re
class modules; John & Stephen's book is so much better in that regard.

Better yet, or at least an extremely useful adjunct with compelling
examples, apps, and code, is Goetz and Gilbert's "VBA for Developers"
book (Syquest). That, and help from yuo guys, is what made it click
for me. Too bad VBA wants to make this stuff so opaque, though; give
me C++ <vbg>

Dave Braden

In article <#5H8FfEUBHA.1408@tkmsftngp05>, Chip Pearson
<ch...@cpearson.com> wrote:

--
E-mail (ROT-13'ed): qoe...@ebpurfgre.ee.pbz

Chip Pearson

unread,
Oct 9, 2001, 6:46:34 PM10/9/01
to
Hi Dave,

> Too bad VBA wants to make this stuff so opaque, though; give
> me C++

The Dot.Net platform, which will presumable surface in Office apps in version 11
or 12 as Visual Studio For Applications (VSA) is a major change from VBA.
Syntactically, it is very similar, but structurally it is quite different.
Compatibility will be a huge issue, as the VB people have seen with VB.NET vs
VB6. But VSA will allow things never before imagined with VBA.

If you are really interested in the internal workings of VB/VBA, and how to
exploit them with a TypeLib or two (no idea how this translates to the Mac
platform), I would VERY strongly recommend Matt Curland's "Advanced Visual
Basic" book. I have several VB books, and this is probably the most advanced,
getting into topics like VTables and IUnknown. It really gets into the gory
details of what really happens with objects and so on. I would VERY STRONGLY
recommend this book to the intermediate level VBA programmer.

It takes two good reads to get the concepts. The first read is familiarization
with concepts, and the second read actually makes sense. A third read is
helpful to actually use the code.

This is a HIGHLY recommended book for the advanced-level VB/VBA programmer.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com

"David J. Braden" <no...@ugotta.bekidding.com> wrote in message
news:091020011834182696%no...@ugotta.bekidding.com...

Stephen Bullen

unread,
Oct 10, 2001, 3:28:18 PM10/10/01
to
Hi Chip,

> This is a HIGHLY recommended book for the advanced-level VB/VBA programmer.

Hear, Hear - apart from the fact that moving to VB.Net renders nearly all of
it obsolete.

Regards

Stephen Bullen
Microsoft MVP - Excel
http://www.BMSLtd.co.uk or http://208.49.24.208


Chip Pearson

unread,
Oct 10, 2001, 3:48:01 PM10/10/01
to
> Hear, Hear - apart from the fact that moving to VB.Net renders nearly all of
> it obsolete.

I know! Once I finally understood what he was talking about, MS releases a
product that changes it all. Oh, well, another excuse to buy more books.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com


"Stephen Bullen" <Ste...@BMSLtd.ie> wrote in message
news:VA.000008a...@bmsltd.ie...

David J. Braden

unread,
Oct 10, 2001, 7:48:33 PM10/10/01
to
Renders nearly all of *what* obsolete? Classic VBA? Or does the move to
VB.Net render *it* obsolete? And how?

TIA
Dave Braden

In article <VA.000008a...@bmsltd.ie>, Stephen Bullen
<Ste...@BMSLtd.ie> wrote:

--
E-mail (ROT-13'ed): qoe...@ebpurfgre.ee.pbz

Chip Pearson

unread,
Oct 11, 2001, 12:56:27 AM10/11/01
to
Hi Dave,

> Renders nearly all of *what* obsolete? Classic VBA?

Stephen and Rob are more qualified than I to answer your question, but what
hell, I'll give it a shot. MS is in the process of "dumping" what could be
called "classic VB", and VBA is really "son-of-VB", in favor of the entire
so-called "DOT.NET" platform. This will replace VB6 with what is called VB.NET.
C++ remains the same, but an entire new language called C# (pronounced C-Sharp)
has been created to replace Java/J++. MS is abandoning Java in favor of C#.

On the VBA side, the logical replacement is called VSA or Visual Studio For
Applications. This is based on the VB.NET language. It is an impressive
platform. I've played with it a little bit, and I like it. There is a very
steep "learning curve" simply because the capabilities are so much more than
"classic" VBA.

The differences and similarities between VB "classic" and VB.NET are too
extensive to list in a newsgroup post. Take a look at the last 10 Zillion
messages over in the VB newsgroups, and you'll get an idea. The VB folks are
not happy. It is not the case that VB.NET is a "bad" language, it is really
that it isn't compatible with the trillions of lines of existing code.

Syntactically, VBA and VSA (like VB "classic" and VB.NET) are rather similar.
However, the underlying architecture is profoundly different. While you'll be
able to read VSA and understand what it is doing, you may not be able to simple
"translate" VBA into VSA. MS hasn't announced if or when VSA will find its way
into Office, but a reasonable assumption would be Office 11 or 12, which means
we'll see it in around 3 years. VSA and VB.NET are very nice, but backwards
compatibility and porting issues are HUGE. We can hope that the Office group
will learn some lessons from what the VB group is going through now, and make
our transition easier.

I like VSA and VB.NET as a *new* development platform. VSA/VB.NET really takes
the basic VB language to a whole new level. It is very nice. BUT.... you lose
compatibility with old code. No one outside of MS knows how and when VB.NET/VSA
will come into the Office platform. And no one knows what that will mean for
compatibility with earlier versions. The only real guess is that MS has another
two years to figure it out, and they've already gotten TONS of feedback from the
VB community.

It is a whole new world, but nothing that Office/VBA programmers will see for
another two or three years.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com


"David J. Braden" <no...@ugotta.bekidding.com> wrote in message

news:101020011948339594%no...@ugotta.bekidding.com...

David J. Braden

unread,
Oct 11, 2001, 3:35:06 AM10/11/01
to
Chip,
*now* you are showing the good stuff. Thanks so much. This time 'round
you actually make sense. Scary thought.

Regards,
Dave Braden

In article <OCabeEhUBHA.1424@tkmsftngp03>, Chip Pearson

Stephen Bullen

unread,
Oct 11, 2001, 5:19:21 AM10/11/01
to
Hi David,

And just to bring Chip's comments back to Matt's book:

> > Syntactically, VBA and VSA (like VB "classic" and VB.NET) are rather similar.
> > However, the underlying architecture is profoundly different.

Matt's book details *exactly* what goes on behind the scenes - i.e. how VB stores
and manages the code, variables etc that you create. By knowing what's going on
behind the scenes, we can read/write to those memory addresses and get VB to do
some rather interesting things <g>. As VB.NET uses a completely new
architecture, there's very little of Matt's book that's still relevant in the
Net world.

0 new messages