jeffreyweir
Active Member
Howdy folks. I've been doing some testing on an Excel .XSLM file with data in the entire column A of Sheet 2 i.e. a header in A1 and data from A2 to A1048576 i.e. the entire column.
I found that using SELECT * FROM [Sheet2$] works just fine, and pulls through the entire 1048765 records. But any time you want to return data from a named range on that sheet rather than just a blanket "Give me the entire sheet" i.e. [Sheet2$] then you get unexpected results:
1. SELECT * FROM [Sheet2$A:A] only returns 65535 records:
2. SELECT * FROM [Sheet2$A1:A1048576] returns an error: "The Microsoft Access database engine could not find the object 'Sheet1$A1:A65537'
There's nothing wrong with my syntax or connection strings.
So this returns 65535 records: SELECT * FROM [Sheet$A1:A65536]
...whereas if I ask for just one more record beyond old Excel's grid size, it errors out: SELECT * FROM [Sheet$A1:A65537]
...even though SELECT * FROM [Sheet2$] works just fine, and pulls through the entire 1048765 records.
So I'm thinking this is a bug. MS obviously haven't programmed their driver to handle the bigger grid whenever you are using range references.
Funny thing is that setting up a MS Query connection using ODBC works just fine.
Anyone have any thoughts they can share on this?
I've also posted this at a linked in group I'm a member of: http://www.linkedin.com/groups?home=&gid=58704&trk=anet_ug_hm
Here's my code, for what it's worth:
I found that using SELECT * FROM [Sheet2$] works just fine, and pulls through the entire 1048765 records. But any time you want to return data from a named range on that sheet rather than just a blanket "Give me the entire sheet" i.e. [Sheet2$] then you get unexpected results:
1. SELECT * FROM [Sheet2$A:A] only returns 65535 records:
2. SELECT * FROM [Sheet2$A1:A1048576] returns an error: "The Microsoft Access database engine could not find the object 'Sheet1$A1:A65537'
There's nothing wrong with my syntax or connection strings.
So this returns 65535 records: SELECT * FROM [Sheet$A1:A65536]
...whereas if I ask for just one more record beyond old Excel's grid size, it errors out: SELECT * FROM [Sheet$A1:A65537]
...even though SELECT * FROM [Sheet2$] works just fine, and pulls through the entire 1048765 records.
So I'm thinking this is a bug. MS obviously haven't programmed their driver to handle the bigger grid whenever you are using range references.
Funny thing is that setting up a MS Query connection using ODBC works just fine.
Anyone have any thoughts they can share on this?
I've also posted this at a linked in group I'm a member of: http://www.linkedin.com/groups?home=&gid=58704&trk=anet_ug_hm
Here's my code, for what it's worth:
Code:
Sub SQL_test()
Dim con As ADODB.Connection
Dim rstData As ADODB.Recordset
Dim sDatabaseRangeAddress As String
Set con = New ADODB.Connection
Set rstData = New ADODB.Recordset
con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ActiveWorkbook.FullName & ";Extended Properties = ""Excel 12.0 Macro;HDR=Yes"";"
rstData.Open "SELECT * FROM [Sheet1$A1:A65537]", con
Range("F1").Value = "Results"
Range("f2").CopyFromRecordset rstData
rstData.Close
Set rstData = Nothing
Set con = Nothing
End Sub