Does anyone know if there is a similar command to use with ADO for copying entire recordsets into a worksheet. The CopyFromRecordSet command (DAO command) doesn't work with ADO.
It's not ADO that has the CopyFromRecordset method, its Excel:
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQl as String
strSQL = "Select * from tblSomeTable"
conn.CursorLocation = adUseClient
Set rs = conn.Execute(strSQL)
'Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application"
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
'Transfer the data to Excel
oSheet.Range("A1".CopyFromRecordset rs
'Save the Workbook and Quit Excel
oBook.SaveAs "C:\Book1.xls"
oExcel.Quit
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.