Excel 范围为的自动化错误。记录集方法

Excel 范围为的自动化错误。记录集方法,excel,vba,Excel,Vba,我在执行这行代码时遇到了一个问题,这行代码包含在一个userform中: Dim RS As ADODB.Recordset Set RS = CreateObject("ADODB.RecordSet") 'omitting the queryString and connection parameters - I'm highly certain the issue doesn't lie there RS.Open queryString, cn 'Declare t

我在执行这行代码时遇到了一个问题,这行代码包含在一个userform中:

 Dim RS As ADODB.Recordset
 Set RS = CreateObject("ADODB.RecordSet")

 'omitting the queryString and connection parameters - I'm highly certain 
  the issue doesn't lie there

 RS.Open queryString, cn

 'Declare the object
 Dim classCutCells As Range

 'The next 2 lines are 1 in the actual code, just broke it up here for readability
 Set classCutCells = reisWS.Range(reisWS.cells(classCutRow, classCutCol),  _
     _ reisWS.cells(classCutRow + RS.RecordCount, classCutRow + RS.Fields.Count))

 'The following line produces the error
 classCutCells.CopyFromRecordset (RS)
当click事件关闭时,我得到以下错误:

Run-time error '430': Class does not support Automation or does not support expected interface.
我目前的参考资料包括:

Visual Basic for Applications
Microsoft Excel 14.0 Object Library
OLE Automation
Microsoft Forms 2.0 Object Library
Microsoft Office 14.0 Object Library
Microsoft Scripting Runtime
Microsoft Windows Common Controls 6.0 (SP6)
Microsoft Visual Basic for Applications Exentisibility 5.3
Microsoft ActiveX Data Objects 6.0 Library

当我介入调试,并将classCutCells.CopyFromRecordset(RS)传递到即时窗口中时,代码工作正常,数据被放入所需的范围。我想这可能是一个参考问题,但在网上找了几天之后,我没有发现任何东西。有什么想法吗?

显然,当您用括号调用CopyFromRecordset(RS)方法时,它需要一个变量。我将RS从括号中移出,现在它可以工作了。如果我得到的是一个类型错误,而不是这个自动错误,这将在上周得到解决。

什么类型的声明有
RS
?@lowak RS是ADODB.Recordset-更新了上面的代码。是的,在VBA中调用参数时,围绕参数的假括号遵循传统的解释,即请求复制参数(通常是为了防止被调用的子例程修改它)。这仅适用于对象,前提是存在用于创建对象浅层副本的接口。这就是它失败的原因,不是因为它是一个变体。