![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
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?
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
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 |
|
|
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thank you very much for taking the time to help me out. I will give this a try.
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|