+ Reply to Thread
Results 1 to 13 of 13

Using Classes In Multiple Projects

  1. #1
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20

    Using Classes In Multiple Projects

    Hi

    I am trying to replicate the class example on Chip Pearson's site:

    http://www.cpearson.com/excel/Classes.aspx

    In particular I am interested in having a class that can be accessed by multiple workbooks.

    Please can you let me know why this will not compile?

    Thanks for your help!
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441
    You need to read the instruction carefully.

    Back in the project containing the class, create a procedure that will create and return a new instance of the class:
    The GetClass function needs to be in a module not the class.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20
    thanks Andy

  4. #4
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20
    I have a new problem now that is when I try to initialise the class in a different workbook it will not compile saying user defined type not defined.

    Any idea what I have forgotten to do?

    Thanks again

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441
    Did you include a reference to the project with the class in it?

  6. #6
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20
    No - please let me know how to reference it.

    Thanks

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441
    Tools > References
    The project name should be in the list.

  8. #8
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20
    Thanks!!!!!!!!!!!

  9. #9
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20
    I have a new problem. The module that is using the class saved in another workbook has an object that needs to be available to the class. The project will not compile because the class cannot reference the object error: variable not defined.

    The object is set as public so I don't know what else to try. Is it even possible?

    Thanks for your help
    Jack

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441
    What object?

    Can you post your files. Both the one holding the class and the one trying to use it.

  11. #11
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20
    Please see attached files. It won't compile due to the 'fund' and 'ccy' objects not being available to the class.

    Thanks...
    Attached Files Attached Files

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441
    You need to pass the information to the class. It can not "see" the variables in the other project.

    Add to new Set statements to the class.
    Make the assignments in your main project.
    Amend code in class to handle local references.

    project code
    Please Login or Register  to view this content.
    Class code
    Please Login or Register  to view this content.
    You should also add objects to allow referencing to local sheets.
    Otherwise writing a class with specific sheet references and hoping the active workbook is relevant sort of defeats the point of using a class across projects. You might as well copy the whole class code over.

  13. #13
    Registered User
    Join Date
    09-11-2008
    Location
    London
    Posts
    20
    Thanks for all your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pasting multiple lines of text into one cell
    By hoopz in forum Excel General
    Replies: 4
    Last Post: 07-11-2012, 08:28 PM
  2. spreadsheet for multiple users
    By evanzo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2008, 11:04 PM
  3. Multiple charts over multiple sets of data over multiple worksheets.
    By matrocka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2007, 10:01 AM
  4. Count unique logs with multiple conditions of multiple sheets
    By Robert Bob in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-12-2007, 12:49 AM
  5. AAAaaahhhh Multiple Sheets Multiple Criteria
    By Hippychic in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-07-2006, 11:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1