Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default open range (within workbook) as ado recordset - excel vba

Rather than fill the ADO recordset with a query, you might consider creating
a disconnected recordset and filling it by iterating through the rows and
columns of your sheet. Once you've done this, the recordset may be easily
passed around and used like any other recordset.

Dim rs As New ADODB.Recordset

rs.Fields.Append "Field1Name, adInteger
rs.Fields.Append "Field2Name", adInteger
etc
rs.Open
rs.AddNew
rs!Field1Name = mysheet.cells(iRow,iCol)
rs!Field2Name = mysheet.cells(iRow,iCol+1)
etc.
rs.Update save the record



"brian" wrote in message
om...
Hi

I have a table of data on an excel worksheet and i would like to put
the table into an ado recordset to perform some data manipulation.
It's easy to find out how to do this from a vb app using an external
xls file, but how do i do it from vba within the spreadsheet?

I want to do something like this (see below) without opening an
external file - is there something you can set the Data Source to
which lets you access worksheets in the currently open workbook? Maybe
an equivalent of Currentproject.Connection in Access??? Or am i
barking up the wrong tree?

Thanks
Brian

Dim rsData As ADODB.Recordset
Dim szConnect As String
Dim szSQL As String
Dim strFilePath As String

strFilePath = "C:\whatever.xls"

szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilePath & ";" & _
"Extended Properties=""Excel 8.0;HDR=No;"""

szSQL = "SELECT * FROM [enquiries$B7:N500]"

Set rsData = New ADODB.Recordset

rsData.Open szSQL, szConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Excel, Book1 opens, remains open with other workbook open DanieB Excel Discussion (Misc queries) 0 September 3rd 09 08:23 AM
query a recordset SAm Excel Discussion (Misc queries) 2 May 1st 07 09:33 PM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
Open Workbook - Select Range as table for vlookup Alan Excel Discussion (Misc queries) 4 November 3rd 05 06:56 PM
Excel workbook does not open in open window on desktop DeanH Excel Discussion (Misc queries) 2 March 8th 05 09:51 AM


All times are GMT +1. The time now is 08:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"