以下是我的记录集声明
Dim expectedRs, actualRs As ADODB.Recordset
Set expectedRs = accessDatabse.getResultSetForSqlQuery(tempArr(1))
Set actualRs = accessDatabse.getResultSetForSqlQuery(tempArr(2))
以下工作正常,
excelFunc.writeQueryResultsToExcel( tempArr(0), accessDatabse.getResultSetForSqlQuery(tempArr(1)), accessDatabse.getResultSetForSqlQuery(tempArr(2)))
但是,我无法在方法调用中传递变量
excelFunc.writeQueryResultsToExcel CStr(tempArr(0)), expectedRs,actualRs
我收到编译时错误" ByRef Argument Type Mismatch"
以下是我的函数被调用
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As Object, actualRs As Object)
Dim wkb As Workbook
Dim strPath As String
strPath = globalObj.getDefaultRunInstancePath()
Set wkb = Workbooks.Open(strPath + workbookName + ".xlsx")
'rs.Open strSQL
'Sheet4.Range("A1").CopyFromRecordset rs
'***********************************UntestedCode******************************
wkb.Sheets("Expected").Range("A1").CopyFromRecordset expectedRs
wkb.Sheets("Actual").Range("A1").CopyFromRecordset actualRs
wkb.Save
wkb.Close
'***********************************UntestedCode******************************
End Function
答案 0 :(得分:0)
Dim expectedRs, actualRs As ADODB.Recordset
实际上意味着:
Dim expectedRs As Variant, actualRs As ADODB.Recordset
您的函数预计expectedRs
Object
和actualRs
也是Object
。因此,请做以下更改:
Dim expectedRs, actualRs As ADODB.Recordset
更改为:
Dim expectedRs As ADODB.Recordset, actualRs As ADODB.Recordset
和
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As Object, actualRs As Object)
更改为:
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As ADODB.Recordset, actualRs As ADODB.Recordset)