Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Data from First Worksheet in XLS File 1

Status
Not open for further replies.

TheInsider

Programmer
Jul 17, 2000
796
CA
Not sure if this is the correct forum, but hopefully someone will know the answer:

I'm trying to use ADO and SQL (in an Access VBA module) to select data from the first worksheet of any xls file that I choose. The problem is I have several xls files with similar data, but each has a different name for the first worksheet.

Therefore, the following doesn't work:

SELECT * FROM [Sheet1$];

Does anyone know how to get the name of the first worksheet in an xls workbook via ADO or what syntax to use in my SQL statement above?

TIA!
 
This will loop throught the sheets returning it's name. I use this looking for a specfic sheet. You must be aware sheets can be in any order.

For i = 1 To XFile.Application.Sheets.Count
strName = XFile.Application.Sheets(i).Name
Next i
 
Thank you bubba100. I actually ended up just using [A1:Z65535] in my SELECT statement, which defaults to the first worksheet and crops the range to the actual data. Since my data won't go beyond column Z, this works quite well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top