Default Methods
VBA does not directly support the creation of a default member of a class.
If you are working with classes in VBA (see Class Modules for more details) it is often useful to make one member of a class the default member.
For example, in the Excel Range object, the default member is Value.
Creating A Default Member
To specify a method as the default member, you need to
(1) Export the class module to a text file.
(2) Add an Attribute directive to the method.
(3) Import the text file back into the VBA Project.
Attribute Value.VB_UserMemId = 0
An Attribute directive is an instruction to the compiler indicating various conditions for compilation.
The Attribute directives are not visible in the VBA Editor and they cannot be added by the VBA Editor.
You must use a text editor to add Attribute directives.
If you want to make the Value property the default member of your class, your code needs to look like this:
Property Get Value() As Long
Attribute Value.VB_UserMemId = 0
Value = Whatever
End Property
You can make a Sub, Function, or Property the default member of the class, but only one procedure in the module can be the default member.
Once the file has been back into the VBA Editor, you will not see any changes in your code.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext