VBA - 调用一个模块带来一个字符串和完整的Query

VBA - Call a module to brings a string and complete Query

对 VBA 很陌生。我试图自己解决这个问题,但任何公开的威胁似乎都符合我的需要。

上下文: 我有这个从 DDBB 获取信息并将其复制到新工作簿中的宏。我想在与主要模块不同的模块中组织不同的查询,并按需调用它们。

问题: 我在新模块中将查询设置为字符串,但始终找不到 ByRef 或 Method 或 data member:

主副

Sub Consulta_Sql_ERP()

'Declare variables
    Set objMyConn = New ADODB.Connection
    Set objMyRecordset = New ADODB.Recordset
    Dim strSQL As String
    Dim ws2 As Workbook
    Dim iCols As Integer


'Open Connection'
    objMyConn.ConnectionString = "Provider=SQLOLEDB.1;
                                  Data Source=(...);
                                  Initial Catalog=(...);
                                  User ID=(...);
                                  Password=(...);
                                  Persist Security Info=True;"
    objMyConn.Open

    'Set and Excecute SQL Command'

        strSQL = Module4.Querys(Query1)

'Open Recordset'
    Set objMyRecordset.ActiveConnection = objMyConn
        objMyRecordset.Open strSQL

'Open a NewWorkbook
    Call NewBook

'Copy Data to the new book
    Set ws2 = ActiveWorkbook
        ws2.Worksheets("Sheet1").Activate

'Copy headers
    For iCols = 0 To objMyRecordset.Fields.Count - 1
        Worksheets("Sheet1").Cells(1, iCols + 1).Value = objMyRecordset.Fields(iCols).Name
    Next

    ActiveSheet.Range("A2").CopyFromRecordset (objMyRecordset)
    objMyConn.Close

'Close and save
    Call carpetaventas
    'ws.SaveAs Savechanges:=True, Filename:="" & Format(Date, "yyyymmdd")
    'ws2.Close Savechanges:=True, Filename:="" & Format(Date, "yyyymmdd"), 
    'RouteWorkbook:="C:\Ventas"    
End Sub

我的查询字符串所在的模块是 "Module4"

我有我的查询的子:

Sub Queries(Query1 As String)
Set Query1 = "Select * from table1"
End Sub

如果我在 "strSQL" 之后直接引入查询,但如果我 "call" 在 Module4 上引入 Sub,则无效。有任何想法吗?

非常感谢。

strSQL = Module4.Query1()


Function Query1() As String
    Query1 = "Select * from table1"
End Sub