Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

excel - VBA returning error when calling a Sub with multiple parameters

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.

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 generateURL(row As Long, column As Long)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When calling more than 1 parameter (i.e. just generateURL(n) works) you need to either use

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

using Call is the better programming technique as it is clearer

As per 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...