Link to home
Start Free TrialLog in
Avatar of mcs26
mcs26

asked on

Making VBA Class Module Library

Hi,

I have made an Excel Project library with some class modules following the examples on this link http://www.excelforum.com/excel-programming/526431-make-vba-class-module-library.html So i have been able to create a reference in a new workbook to 'MyProj'.

When I define Obj as MyProj.MyClass it works fine to, the intellisense works. The issue comes on the line Set ObjMyProj.GetMyClass1() (from the webpage) and I have checked the function name is correct and things like that. It just highlights the GetMyClass1 & says Method or data member not found? In the object browser though I can see the method??

Thanks,



Avatar of Member_2_6169280
Member_2_6169280
Flag of United States of America image

Avatar of mcs26
mcs26

ASKER

Hi Royhsiao,

I have just been looking at the cpearson example thanks. I cannot see where I have gone wrong. The workbook that contains the class modules is just a normal workbook, does that make a difference.

When I type "Set obj = MyProj." the intellisense list the the worksheets and the workbook.

If I just type "obj." the intellisense populates with the functions in the class, but obviously at run time it does not work with the error message 'object not set etc'

Thanks,
I think you are trying to distribute your code using references.
Here is the easier way to reference to the macro on another worksheet.
1) write the code in module start with public xxxx and change the VbaProject name
2) click tools, reference, browse, and select the workbooks.
3) make sure the workbook is in the references folder
4) you could just use call to use the code in another project

see the following picture and let me know if you have more questions.

Basically, you are creating a add in like xla file and here is the post about creating the add-in.
http://www.cpearson.com/excel/createaddin.aspx

reference.JPG
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mcs26

ASKER

Hi Royhsiao,

Thanks for the link on the addinn. I understand what you are saying and agree that this way is fine. However I'm just trying to find out how to make a library.

Cheers,
Avatar of mcs26

ASKER

Hi rorya,

Thanks for the reply. I put the Public Function GetMyClass1 inside the class module - is that wrong?

Thanks,
Yes - it needs to be in a normal module, since it returns an instance of the class.

If the code is in the class, then you need an instance of the class to call the code, and you can't get an instance of the class until you call the code, so it's Catch 22. ;)