Class in separate add in?

C

Chuck

I'm trying to get my head around classes ... ideally I'd like to create add
ins that contain code used by a variety of subs in other add ins. I'm using
a progress bar form as my learning tool -- for instance ideally any sub in
any add in would be able to call up the progress bar from a single dedicated
add in; the alternative seems to be to copy the progress bar code to every
add in.

Is it possible to use a class that exists in a different add in? When I set
up a class in one add in and add a reference to it in second, the second only
sees the first's modules and ThisDocument. Do I need to create a sub in a
module in the first add in that allows the second to manipulate the class in
the first?

Apologies if this is a murky question. Any guidance much appreciated...

Should I be creating mac
 
J

Jezebel

You can add a property to the module that instantiates and returns a
reference to the class. Eg the addin called XXX has a class called clsPBar;
in a module in the addin add code like this --

Public Property Get PBarClass() as clsPBar
Set AddinClass = new clsPBar
End Property

Then any module with a reference to the addin can use

With XXX.PBarClass
....


You'll need to modify the property code if you don't want to instantiate a
new class object with every call -- eg if you have just one instance shared
by all callers.
 
C

Chuck

Thanks Jezebel, -- I'm able to see the subs in the add in's class from the
calling macro now. Am I correct in assuming that the only way I can call on
another template's classes is to make sure I have a reference to that
template in my calling project? Or is there another way of accessing another
template's classes without ticking off a reference to it?

Thanks again...
 
J

Jezebel

Yes, you have to have a reference to it.




Chuck said:
Thanks Jezebel, -- I'm able to see the subs in the add in's class from the
calling macro now. Am I correct in assuming that the only way I can call
on
another template's classes is to make sure I have a reference to that
template in my calling project? Or is there another way of accessing
another
template's classes without ticking off a reference to it?

Thanks again...
 

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