您好我在excel 2013 vba工作,我想将工作表对象传递给类函数:
'类模块Class1'
Sub receive(ByRef ws As Worksheet)
msgbox ws.name
End Sub
使用以下方法调用类方法:
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
一个有效的简单测试是同一个模块中的两个子程序:
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
我在概念上缺少什么?
提前致谢!
答案 0 :(得分:5)
您需要从通话中删除括号:
def clas
@classtimetable = Timetable.where(timetable_params[:clas]).first
end
或添加myClass.receive ws
关键字:
Call
只有在调用例程时才需要括号:
Call myClass.receive(ws)
关键字;或