I am calling an object's subroutine in Microsoft excel vba. The sub has 2 parameters, both objects themselves. The line of code I typed is giving an error-> Compile Error: Expected =
Here is the section of code that it occurs in:
' 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
I don't understand why this is. This code is similar to code I already have that works fine.
This code works perfectly (Note: this is a separate 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
This is how I am declaring the subroutine that I am calling that gives the compile error:
Public Sub loadFromAnotherWorkbook(ByVal wb As Workbook, ByVal wbColumns As CColumns)
The objects I pass into this sub are of the correct type.
This isn't a function, so I don't understand why I would need to use an equal sign. Anyone know what I am doing wrong?