Custom Class Library

G

Guest

Guest
I would like to create an add-in with one or more custom classes. Then, as long as the add-in is loaded, I would like to be able to create objects of type "custom class" (as defined in the add-in) witin other workbooks. Is this possible?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
This is a tricky one and something which took me ages to work out when trying this before.

In your add-in add a function like this in a standard module:-

Public Function ReturnClass() As ProjectName.Class1
Set ReturnClass = New Class1
End Function


Where ProjectName is the name of your add-in as specified in the Properties window when you select the add-in.

Now, in the workbook where you want to use the classes try this:-

Select a reference to the add-in from Tools, References. Then you'll be able to do this:-

Dim c As ProjectName.Class1

Sub test()
Set c = ProjectName.ReturnClass
c.DoSomething
End Sub

I don't believe you can directly create classes defined in another project, but this seems to work well enough. Please let me know if something is unclear.

Regards,
D
 
Upvote 0
Thank you very much for taking the time to help me out. I will give this a try.
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,384
Members
448,889
Latest member
TS_711

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top