在VBA中使用多个参数调用Sub

时间:2019-05-22 14:46:58

标签: excel vba

我想用多个参数调用sub,但是出现错误语法错误

我在Excel 2013女士上尝试过

Sub Withdrawal(Query As String, Savelocation As String)

    'Query Data
    Dim ReturnArray
    Dim Conn As New ADODB.Connection
    Dim mrs As New ADODB.Recordset
    Dim DBPath As String, sconnect As String
    DBPath = Application.ActiveWorkbook.Path + "\Data.xlsx"
    sconnect = "Provider=MSDASQL.1;DSN=Excel Files;DBQ=" & DBPath & ";HDR=Yes';"
    Conn.Open sconnect
    mrs.Open Query, Conn
    ThisWorkbook.Worksheets(Savelocation).Range("A3").CopyFromRecordset mrs
    mrs.Close
    Conn.Close
End Sub

Sub CashWithdrawal()
    Dim CashWFYC As String
    Dim Location As String
    Location = "CashWithdrawal"
    CashWFYC = "SELECT TOP 10 * FROM [TT$]"
    sSQLSting = CashWFYC 
    Withdrawal(sSQLSting, Location)
End Sub

我希望从该sSQLSting查询获得的输出应保存在Location

1 个答案:

答案 0 :(得分:1)

您应打电​​话时不要带括号。括号内是函数调用。

Withdrawal sSQLSting, Location 

请在代码顶部放置Option Explicit,并声明所有变量(包括显式类型)。