I frequently import data from an Oracle database into Excel so I can work with the data locally without being connected to the Oracle database. My process is to script a query against the Oracle db in a macro and dump the results into a worksheet. Once that is done I can then query the data in Excel using the following code:
strDBpath = ActiveWorkbook.FullName
ActiveWorkbook.Names.Add Name:="MyWorksheet", RefersToR1C1:="=Sheet1!R1C1:R" & lngRowCount & "C6"
Set cnnConn = New ADODB.Connection
cnnConn.Open "Driver={Microsoft Excel Driver (*.xls)};DBQ=" & strDBpath & ";ReadOnly=1"
strMyWSquery = "SELECT customer FROM [MyWorksheet]"
Set rstMyWS = New ADODB.Recordset
rstMyWS.Open strMyWSquery, cnnConn, adOpenStatic
Specifying a workbook Name allows me to query the data with sql statements just like any other ODBC database. However I've run into an Oracle table that contains more than 65534 rows so when I dump it into my workbook I have to split it across two worksheets. The problem I'm having is with trying to combine data from the two worksheets into a single Workbook.Name that I can run queries against. Is there a way to define a Workbook.Name that straddles two worksheets? If not, is there some other way around the problem? To summarize, I want to combine data from two worksheets into a single data source that I can query using common sql language.
Bookmarks