View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Problem in Excel 2007 when Range beyond 65536 in SELECT statement

I'd try a completely different approach. Here's how I would do it...

Sub QueryWorksheet()
Dim rsData As ADODB.Recordset
Dim sConnect As String, sSQL As String

sConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & ThisWorkbook.FullName & ";" _
& "Extended Properties=Excel 12.0;"

sSQL = "SELECT A,B FROM [Sheet1$A66000:E66005];"

Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly, _
adCmdText

'Check to make sure you got data
If Not rsData.EOF Then
Sheet1.Range(A2").CopyFromRecordset rsData
Else
MsgBox "No records returned!", vbCritical
End If
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc