+ Reply to Thread
Results 1 to 4 of 4

"Private object modules cannot be used in public object modules...."

Hybrid View

6StringJazzer "Private object modules... 02-28-2013, 10:07 AM
JosephP Re: "Private object modules... 02-28-2013, 10:21 AM
6StringJazzer Re: "Private object modules... 03-01-2013, 02:32 PM
JosephP Re: "Private object modules... 03-01-2013, 04:07 PM
  1. #1
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,021

    "Private object modules cannot be used in public object modules...."

    This question is for folks who have experience using Classes in VBA. I have done some OOP but not in VBA.

    Quote Originally Posted by VBA Compiler
    Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types.
    Why?

    I have defined a Class, and am using an object of that class as a parameter in a public Sub of a Worksheet module. I get the message above when trying to compile. I cannot think of any reason that this should be prohibited. But I am not here to argue about it, I am here to see how to design around it.

    Attached is a boiled-down example. See the code in Sheet1 and try to compile it. Is there a standard workaround for this?
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: "Private object modules cannot be used in public object modules...."

    either move the sheet code to a normal module or change the instancing of the class (in the properties window) to make it public instead of private
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,021

    Re: "Private object modules cannot be used in public object modules...."

    Thank you for the suggestion, I will give it a try. I haven't found a rigorous definition of what that property means for classes. Private is default but the only other setting is PublicNotCreatable. That seems to imply other restrictions, but I don't know what. This property seems like it should come into play when referencing this class from another project, but my problem is referencing it within the same project. Nevertheless I'll give it a try! Thanks.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: "Private object modules cannot be used in public object modules...."

    yes-publicnotcreatable means that from a referencing project you can declare a variable of that type but you cannot actually create a new instance of it. you need to set the instancing to 5 for that but you can no longer do that in the vbe; you have to export the module and alter the text file

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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