调用具有多个参数的Sub时,VBA返回错误

我想弄清楚为什么VBA返回一个错误(Compile error: Expected: =)当我打电话给一个Sub并提供多个参数。 任何帮助将不胜感激。

 Sub customerController(cleanStructure As Boolean, firstCol As Integer, latCol As Integer, _ lngCol As Integer, Optional startRow As Long, Optional endRow As Long) Dim i As Long, j As Long, n As Long If (cleanStructure = False) Then 'customer data type If (startRow = "") Then i = 1 If (endRow = "") Then j = countRows For n = i To j - i + 1 generateURL(n, firstCol) newReadXMLData (url) ActiveSheet.Cells(i, latCol).Value = lat ActiveSheet.Cells(i, lngCol).Value = lng Next End If End Sub 

我打电话的Sub需要两个参数:

 Sub generateURL(row As Long, column As Long) 

当调用超过1个参数(即只是generateURL(n)作品),你需要使用

  • Call generateURL(n, firstCol)
  • generateURL n, firstCol

使用Call是更好的编程技术,因为它更清晰

根据MSDN:

您通常使用Call语句来调用不返回值的过程。 如果过程返回一个值,那么Call语句会丢弃它。 调用过程时不需要使用Call语句。 但是, 它提高了代码的可读性