ADO to get recordset into array from a workbook

  • Thread starter Thread starter dovrox
  • Start date Start date
D

dovrox

How do I use ADO to get a decordset into an array with data from
closed workbook???
 
The workbook becomes the data source, GetRows puts it in an array

Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim sFile As String
Dim oOrig As Worksheet
Dim osh As Worksheet
Dim oCell As Range
Dim aryData

sFile = "C:\myTest\Volker1.xls"

' Create the connection string.
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFile & ";" & _
"Extended Properties=Excel 8.0;"

' Query based on the worksheet name.
sSQL = "SELECT * FROM [Sheet1$]"

Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, 0, 1, 1

If Not oRS.EOF Then
aryData = oRS.getrows()
Else
MsgBox "No records returned.", vbCritical
End If

MsgBox "Cell A2 contains " & aryData(0, 0)
MsgBox "Cell D4 contains " & aryData(3, 2)

' Clean up our Recordset object.
oRS.Close
Set oRS = Nothing



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top