ByVal or ByRef - Classes

The Class data type is a reference data type.
When you declare a variable with a Class data type it can be passed in using either ByRef or ByVal.
In VBA all reference data types are passed by reference although there is a subtle difference.
Although it is a Reference data type there is a subtle difference between passing ByRef vs ByVal 'myClassModule class module



ByRef

Passing a class into a subroutine using ByRef allows the original class to the changed.


ByVal

Passing a class into a subroutine using ByVal allows the original class to the changed.


What is the difference between ByVal and ByRef in the context of Class data types ?
There is a difference between declaring a variable with a Variant data type as opposed to a Class data type.



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext