PC Review


Reply
Thread Tools Rate Thread

ADO limitation to number of excel 2007 columns??

 
 
pb
Guest
Posts: n/a
 
      4th Mar 2007
Hello all,

The following VBA code should theoretically return all the column
names from an Excel 2007 sheet. What I find is that it only returns
the first 255 even though there are many more in the spreadsheet (a
new feature of excel 2007).

Can anyone tell me how to resolve this?

Thanks,

Phil

Private Sub getXL2007ColumnNames()

Dim count As Integer
Dim fName As String
Dim sheetname As String

Dim cnSim As New ADODB.Connection
Dim rsSchema As New ADODB.Recordset

fName = "C:\demo data\myfile.xlsx"
sheetname = "mysheet$"

Set cnSim = New ADODB.Connection

'cnSim.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=" & fName & ";Extended Properties=""Excel 12.0;HDR=YES"";"
cnSim.ConnectionString = "Driver={Microsoft Excel Driver (*.xls,
*.xlsx, *.xlsm, *.xlsb)};DBQ=" & fName
cnSim.Open

Dim aRestrictions As Variant
aRestrictions = Array(Empty, Empty, sheetname, Empty)
Set rsSchema = cnSim.OpenSchema(adSchemaColumns, aRestrictions)

rsSchema.MoveFirst
Do Until rsSchema.EOF = True
count = count + 1
Debug.Print (rsSchema!Column_Name)
rsSchema.MoveNext
Loop

MsgBox "Fields = " & count

rsSchema.Close
Set rsSchema = Nothing
cnSim.Close
Set cnSim = Nothing

End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
XL 2003 VBA form Listbox-limitation in max number of columns =?Utf-8?B?U2FqZWV0aA==?= Microsoft Excel Programming 3 1st Mar 2007 10:49 PM
Number of Excel 2007 Columns =?Utf-8?B?SmFja0xhbmNhc3Rlcg==?= Microsoft Excel Misc 2 31st Jan 2007 11:17 PM
Any way to get around the number of columns limitation? 43fan Microsoft Excel Discussion 5 11th Oct 2005 12:47 AM
limitation on number of arguments for VB func. called from excel? =?Utf-8?B?VG9uaWEgVC4=?= Microsoft VB .NET 2 30th Oct 2004 08:32 PM
DataAdapter number of columns limitation? Kamil Microsoft ADO .NET 2 3rd Dec 2003 11:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:29 AM.