Methods

These are the actions that can be performed by (or on) the object.
A method is an action that is associated with the object.
These are often actions that cause something to happen on an object.
Methods can have arguments and a return type.
A method can be thought of as an action for an object.


No Return Type

The simplest method would have no parameters and no return type.



Return Type

Public Function Method_WeeklyPay(ByVal dbHourlyRate as Double) As Double 
   Method_WeeklyPay = (field_dbNormalHours + field_dbOvertimeHours) * dbHourlyRate
End Function


Arguments

Methods may require extra information to be supplied as arguments.
It may or may not have a return value and is more likely to have parameters than a property.


Optional Arguments

Methods can also have optional arguments.


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