Custom Class Library

  • Thread starter Thread starter Guest
  • Start date Start date
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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

Forum statistics

Threads
1,223,516
Messages
6,172,778
Members
452,477
Latest member
DigDug2024

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