我在Excel VBA中编写了一个小类,其中包含一个以Range为参数的子类。但是当我尝试使用单元格调用它时,我得到类型不匹配错误。 (使用Range调用工作正常)
代码摘录:
Dim Com, Gua As Worksheet
Set Com = Worksheets(cCom)
Set Gua = Worksheets(cGua)
Dim myFirm As clsFirm
Set myFirm = New clsFirm
Call myFirm.Init(Gua.Cells(3, 4)) '<--ERROR HERE
Call myFirm.Init(Gua.Range("E3")) ' this line works
这是次要的:
Public Sub Init(nameCell As Range)
pAddress = nameCell.Address
pName = nameCell.Value2
pContract = nameCell.Offset(0, -3).Value2
pAmount = nameCell.Offset(0, 2).Value2
pRate = nameCell.Offset(0, 1).Value2
pStartDate = CDate(nameCell.Offset(0, -2).Value2)
pEndDate = CDate(nameCell.Offset(0, -1).Value2)
End Sub