Using classes defined in an add-in

  • Thread starter Lieven Mettepenningen
  • Start date
L

Lieven Mettepenningen

Hello,

I'm having the following problem. I've defined a class module in an add-in,
and I want to use this class module in a workbook that uses this add-in. The
name of the class is 'DictionaryClass'. But when I enter the following line
in my workbook: 'public dict as DictionaryClass', I get a runtime-error,
because Excel complains that it doesn't know the user-defined type. Is there
a special syntax for such a use? I already managed to do this for the
initialization of the object. I first entered: 'Set dict = new
DictionaryClass', but this also gave a runtime-error. I then made a public
function in one of my code modules in the add-in that creates a
DictionaryClass-object, and returns it to the workbook, and I called this
public function from my workbook with the notation 'Application.Run.....'.
Does anyone know if I can do a similar thing for the declaration of the
object.

The important thing is that I use the add-in, but I DON'T want to use a
reference to the add-in. That's also the reason why a have to use the
"Application.Run"-syntax. Can anyone help me with this problem?

Thx,

Lieven
 
C

Chip Pearson

Lieven,

If you don't want to set a reference to the add-in, you need to
declare the class variable As Object, and use Application.Run to
get a reference to the newly created object (created by the code
in the add-in). E.g,

Dim MyClass As Object
Set MyClass = Application.Run("Addin.xla!GetClass")


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

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