|
原本能正常运行的调用,但重装系统(XP)后,重装原版本的Office(2003),运行出错。提示为(运行时错误“-21473919779(8002801d)方法'CopyFromRecordset'作用于对象'Range'时失败)。程序如下:
Sub ±íÉú³É(StrRS2 As String, StrRs3 As String, TXT As String)
Dim Rs2 As Recordset, Conn2 As Connection
Dim objXL As Excel.Application
Dim xlWBWK As Excel.Workbook
Dim T As Integer
Set Rs2 = New ADODB.Recordset
Set Conn2 = CurrentProject.Connection
Rs2.Open StrRS2, Conn2, adOpenKeyset, adLockReadOnly
T = Rs2.RecordCount
If T > 0 Then
Rs2.MoveFirst
Set objXL = New Excel.Application
Workbooks.Open Filename:=StrRs3
Set xlWBWK = ActiveWorkbook
Worksheets(TXT).Range("A2").CopyFromRecordset Rs2
ActiveWorkbook.Save
ActiveWorkbook.Close
Set objXL = Nothing
Set xlWBWK = Nothing
End If
Rs2.Close
Set Rs2 = Nothing
Set objXL = Nothing
End Sub |
|