调用具有多个参数的 Sub 时 VBA 返回错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13624279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA returning error when calling a Sub with multiple parameters
提问by MartinUKPL
I'm trying to figure out why VBA
is returning an error (Compile error: Expected: =)
when I call a Sub
and supply it with multiple parameters.
我试图弄清楚为什么在调用 a并为其提供多个参数时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
The Sub
that I'm calling requires two parameters:
在Sub
这我打电话需要两个参数:
Sub generateURL(row As Long, column As Long)
回答by brettdj
When calling more than 1 parameter (i.e. just generateURL(n)
works) you need to either use
当调用超过 1 个参数(即generateURL(n)
正常工作)时,您需要使用
Call generateURL(n, firstCol)
, orgenerateURL n, firstCol
Call generateURL(n, firstCol)
, 或者generateURL n, firstCol
using Call
is the better programming technique as it is clearer
usingCall
是更好的编程技术,因为它更清晰
As per MSDN:
根据 MSDN:
You normally use the Call statement to call a procedure that does not return a value. If the procedure returns a value, the Call statement discards it. You are not required to use the Call statement when calling a procedure. However, it improves the readability of your code.
您通常使用 Call 语句来调用不返回值的过程。如果过程返回一个值,Call 语句将丢弃它。调用过程时不需要使用 Call 语句。但是,它提高了代码的可读性。