I am trying to implement Inheritance in VBA in the following way –
I have one class module clsRange as shown below
Private strRngName as String
Public Property Let RangeName(ByVal thisRangeName As String)
strRngName = thisRangeName
End Property
Public Property Get RangeName() As String
RangeName= strRngName
End Property
Another class module clsChildRange
private rngHolder as New clsRange
Public Property Get RangeName() As String
Set RangeName = rngHolder.RangeName
End Property
Public Property Let RangeName(ByVal thisRangeName As String)
rngHolder.RangeName = thisRangeName
End Property
I have a module, In that I am trying to create an object for clsChildRange and try to set the properties of clsRange in the following way
Dim objCRng as New clsChildRange
objCRng.RangeName= "Range1"
But I get an error – object variable or with block variable not set.
As Uri said, rngHolder is not instantiated which is causing the problem. Don’t test for Null, but test of Is Nothing. Here are two ways to do this, depending on what you’re trying to accomplish.
Explicitly Set the Range
In CRange
In CChildRange
Then in a standard module
Implicitly set the Range
CRange is the same.
In CChildRange
Then in a standard module