Hi i'm working in excel 2013 vba, I want to pass a worksheet object to a class function:
'Class module Class1'
Sub receive(ByRef ws As Worksheet)
msgbox ws.name
End Sub
Calling the class method receive with:
Sub passToClass()
Dim ws as Worksheet
Set ws = ThisWorkbook.Worksheets("sheet1")
Dim myClass As New Class1
myClass.receive(ws) ' Run-time Error '438': Object doesn't support this property or method
End Sub
A simple test that does work are two subroutines in the same module:
Sub pass()
Dim ws as Worksheet
Set ws = ThisWorkbook.Worksheets("sheet1")
call receive(ws)
End Sub
Sub Receive(ByRef ws As Worksheet)
msgbox ws.name
End Sub
What am I missing conceptually?
Thanks in advance!
Use the Object Browser to determine what members (properties and methods) are available for the selected class (object). Use the IntelliSense feature in the Visual Basic Editor. When you type a period (.) after a property or method in the Visual Basic Editor, a list of available properties and methods is displayed.
You need to remove the parentheses from the call:
myClass.receive ws
or add the Call
keyword:
Call myClass.receive(ws)
Parentheses are only required when calling a routine if:
Call
keyword; orIf 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