调用具有多个参数的Sub时,VBA返回错误 [英] VBA returning error when calling a Sub with multiple parameters
本文介绍了调用具有多个参数的Sub时,VBA返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出为什么 VBA
正在返回错误(编译错误:预期:=)
当我调用一个 Sub
并提供多个参数。任何帮助将被高度赞赏。
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. Any help would be highly appreciated.
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
需要两个参数:
The Sub
that I'm calling requires two parameters:
Sub generateURL(row As Long, column As Long)
推荐答案
当调用多于1个参数(即只是 generateURL(n)
works)您需要使用
When calling more than 1 parameter (i.e. just generateURL(n)
works) you need to either use
-
调用generateURL(n,firstCol)
或 -
generateURL n,firstCol
Call generateURL(n, firstCol)
, orgenerateURL n, firstCol
使用调用
是更好的编程技术,如更清楚
using Call
is the better programming technique as it is clearer
根据MSDN:
您通常使用Call语句来调用不返回值的过程。如果过程返回一个值,则Call语句将丢弃它。
调用过程时,不需要使用Call语句。但是,它提高了代码的可读性。
这篇关于调用具有多个参数的Sub时,VBA返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文