I have a class module, named Normal
, in VBA with the following code:
Private mLine As LineElement
Public Property Get Line() As LineElement
Line = mLine
End Property
Public Property Set Line(ByRef vLine As LineElement)
mLine = vLine
End Property
This class is used by the following code:
Sub Run
Dim Line As LineElement
Set Line = New LineElement
Dim Norm As Normal
Set Norm = New Normal
Set Norm.Line = Line 'FAILS here with "Object Variable or With Block Variable not set"'
End Sub
Also, if I change the code in the Normal
class module to:
Private mLine As LineElement
Public Property Get Line() As LineElement
Line = mLine
End Property
Public Sub SetLine(ByRef vLine As LineElement) 'changed from property to sub'
mLine = vLine
End Property
and the failing line to
Norm.SetLine( Line )
I get an "Object does not support this property or method" error. What exactly am I doing wrong in both of these cases?
A property is an attribute of an object that defines one of the object's characteristics, such as size, color, or screen location, or an aspect of its behavior, such as whether it is enabled or visible. To change the characteristics of an object, you change the values of its properties.
From the View menu of the Visual Basic Editor, choose Properties window (F4). Select the object whose properties you want to display. You can either use the mouse to select the object or use the Project Explorer to choose from a list.
Both properties must have "Set" keyword
Private mLine As LineElement
Public Property Get Line() As LineElement
Set Line = mLine 'Set keyword must be present
End Property
Public Property Set Line(vLine As LineElement) ' ByRef is the default in VBA
Set mLine = vLine 'Set keyword must be present
End Property
Try this:
Private mLine As LineElement
Public Property Get Line() As LineElement
Set Line = mLine
End Property
Public Property Set Line(ByRef vLine As LineElement)
Set mLine = vLine 'Note the added Set keyword in this line'
End Property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With