Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Make VBA Class Module Library

Hi, I have a bunch of class modules that I have made in Excel vba. A bunch
of my Excel programs use them and I was wondering if there is a way to make
them into a library of some sort so that I can have one version of all of
them that each project can link to so I can make a change in one place and
not in each of the projects. Thanks.

Mark
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Make VBA Class Module Library

You can do this, but you've got to jump through a few hoops. Put
all your class modules in one project, and change the name of
that project from the default VBAProject to something unique,
like MyProj. (To do this, in VBA go to the Tools menu, choose VBA
Project Properties, and then change the name.)

Then, ensure that each class module's Instancing property is 2 -
PublicNotCreatable, not 1 - Private. (To do this, open the class
module and press F4 to get the properties window. There, change
the Instancing property.)

The projects that will be using these class modules will be able
to declare a variable with a type of your class, but will not be
able to create a new instance of the class, using the New
keyword. Therefore, in the MyProj project, create a function for
each class module which creates a new instance of the class and
returns it as its return value. For example, if you class is
named MyClass1, your procedure would be

Public Function GetMyClass1() As MyClass
Set GetMyClass1 = New MyClass
End Function

Write a procedure like the above for each class module.

Now, in the project that will be using the class, set a reference
to MyProj (in VBA, go to the Tools menu, choose References, and
select MyProj from the list). Once you've established your
reference, you can write code like


Public C As MyProj.MyClass1
Set C = MyProj.GetMyClass1()


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






"Mark Olsen" wrote in
message
...
Hi, I have a bunch of class modules that I have made in Excel
vba. A bunch
of my Excel programs use them and I was wondering if there is a
way to make
them into a library of some sort so that I can have one version
of all of
them that each project can link to so I can make a change in
one place and
not in each of the projects. Thanks.

Mark



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
How to make a module library. Fabio Excel Programming 7 January 18th 06 09:00 PM
Class Module Todd Huttenstine Excel Programming 2 May 21st 04 11:17 PM
Class module David Excel Programming 4 December 31st 03 01:58 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 10:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"