Saturday, October 06, 2012

How to create a default property in a VBA class

To create a default member in a VBA class you add the attribute...
Attribute MemberName.VB_UserMemId = 0 the second line in the procedure you want to make the default, so something like...
Private m_value As Long

Property Get Value() As Long
    Attribute Value.VB_UserMemId = 0
    Value = m_value
End Property
...makes the Value property the default, but the trick is you can't do it in the IDE's text editor. Export the module as a .cls file and add the attribute in WordPad or NotePad or something, and then re-import the class. The attribute line in the default property will not be visible in the text of the module in the IDE, but you can see in the object browser that member has the default property indicator.

No comments:

Post a Comment