Results 1 to 5 of 5
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Mutually exclusive class attributes? (Office XP SP-2)

    I'm guessing this is not an issue for Visual Studio owners, but here in the wonderful world of Office XP VBA ...

    If you want the VB_Creatable attribute of a class to be True (and yes, I realize there are alternatives to doing that, even if you want to use multiple instances outside the home project), you have to edit the class in Notepad and then use Insert-->File in the VBEditor. (If you Import the edited class, the VB_Creatable attribute flips back to False.)

    On the other hand, if you use Notepad to add the necessary Attribute lines to give a class a default method (e.g., Item), or to allow For Each to be used with a collection class, it seems you have to Import the class for those attributes to take effect. If you use Insert-->File (or do a subsequent Insert-->File), those attributes are lost.

    So I appear to be up against a mutual-exclusivity problem. Is there some way for a lowly Office XP Pro owner to create a class with VB_Creatable set to True and with a default method and For Each capability?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Mutually exclusive class attributes? (Office XP SP-2)

    How about providing information on the specific application you're dealing with. For Each is a standard property of a VB/VBA collection. Is there a collection in your class? Are you talking about a custom user defined object class rather than a class wrapping a built in object?
    Charlotte

  3. #3
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Mutually exclusive class attributes? (Office XP SP-2)

    I was asking on a general basis, not with respect to any particular application or use. By "collection class" I mean a class module wrapping a VBA collection. The [NewEnum] attribute that you need to add to such a class module to be able to use For Each seems to require an Import to take effect (after adding it in Notepad) and to get blown out if you then (or later) use an Insert-->File with that class module -- whereas an Insert-->File seems to be required if you want to change the VB_Creatable attribute to True to have the class be both public and creatable (i.e., directly creatable outside the home project).

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Mutually exclusive class attributes? (Office XP SP-2)

    Hi,
    Have you tried running:
    <pre>Application.VBE.ActiveVBProject.VBComponents( "Classname").Properties("Instancing") = 5
    </pre>

    to set the VB_creatable and Exposed attributes to true?
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Mutually exclusive class attributes? (Office XP SP-2)

    <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> I had not tried running that line, since I was completely unaware that I could manipulate that property with code. And even now that I know what I'm looking for, I can't seem to find that set of properties (I assume "Instancing" is just one of a set) documented in the Help. (I feel a Google coming on...)

    Anyway -- just what I needed! Many thanks.

Posting Permissions

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