具有2个对象参数的Excel VBA对象子调用给出编译错误:expected =

我在Microsoft Excel VBA中调用对象的子例程。 子有2个参数,都是对象本身。 我键入的代码行给出错误 – >编译错误:预期=

以下是它出现的代码部分:

' Copy the info from the old sheet and paste into the new sheet Dim employee as CEmployee For i = 2 To eswbMaxRow Set employee = New CEmployee employee.setNames (eswb.Worksheets("Employee Info").Cells(i, wbColumns.infoNameCol).value) employee.loadFromAnotherWorkbook(eswb,wbcolumns) ' <- This line is giving the compile error Next I 

我不明白这是为什么。 这段代码和我已经有的代码类似,工作正常。

此代码完美工作(注意:这是一个单独的function):

 With ThisWorkbook.Worksheets(sheet) Do While (.Cells(i, 1).value <> Empty) ' Create an object and set the name property Set employee = New CEmployee employee.setNames (.Cells(i, 1).value) employee.loadFromScratch ' <- This sub is nearly identical to the one that is causing the problem. The only difference is it doesn't take object parameters i = i + 1 Loop End With 

这就是我如何声明我所调用的子程序给出了编译错误:

 Public Sub loadFromAnotherWorkbook(ByVal wb As Workbook, ByVal wbColumns As CColumns) 

我传入这个子对象的types是正确的。

这不是一个函数,所以我不明白为什么我需要使用等号。 任何人都知道我在做什么错了?

在调用Sub ,不要将参数括在括号中

像这样使用它

 employee.loadFromAnotherWorkbook eswb, wbcolumns