在 Excel 宏中,我定义了一个函数,像这样返回一个 Recordset
Function GetCommissionDataRecordset(doctorCode As String) As ADODB.Recordset
Set GetCommissionDataRecordset = New ADODB.Recordset
.
. ' setup the connection and SQL string...
.
GetCommissionDataRecordset.Open strSQL
end function
我尝试像这样调用函数
sub tester()
'Dim oRecSet As ADODB.Recordset ' this doesn't work, needs to be a variant
Dim oRecSet As Variant
Set oRecSet = GetCommissionDataRecordset("GC")
'Copy Data to Excel'
ActiveSheet.Range("a1").CopyFromRecordset (oRecSet)
end sub
如果在tester
我定义的子过程中oRecSet as ADODB.Recordset
,我在执行CopyFromRecordset
.
当我定义oRecSet
为Variant
.
运行时错误是430 Class does not support Automation or does not support expected interface
.
发生错误时,Watch 告诉我的类型oRecSet
是Recordset/Recordset
当我使用变体方法时,Watch 告诉我的类型oRecSet
是Variant/Object/Recordset
在 Watch 中检查对象的属性对我来说似乎没有什么不同。
这是怎么回事?