LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Select from first worksheet without knowing it's name

I have an app that reads excel spreadsheets. It works fine, as long as the
first sheet is called "Sheet1". If there is no sheet called Sheet1 it
crashes.

I don't want to force the user to change the spreadsheet, I want to read the
first page no matter what it is called.

Here is how my code works right now:

<code

Dim myds As New DataSet
Dim MyExcelConnectStr As String = "Provider=Microsoft.Jet.OLEDb.4.0;data
source=" & strFileName & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""

strExcelSQL = "SELECT * FROM [Sheet1$]"

Dim MyOleADapter As New OleDb.OleDbDataAdapter(strExcelSQL,
MyExcelConnectStr)

MyOleADapter.Fill(myds, "xlsdata")

intRows = myds.Tables(0).Rows.Count

intFields = myds.Tables(0).Columns.Count

</code

Is there some function or code that can be used in place of:

strExcelSQL = "SELECT * FROM [Sheet1$]"

which will provide the same function (open sheet1) without knowing it's
name? (which may not be Sheet1). Or, a way to GET the first sheets name
(vb.net)?

Thanks.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Knowing the number sadman49 Excel Discussion (Misc queries) 2 March 9th 09 09:15 PM
getting a y-value from a graph knowing the corresponding x-value lsu-i-like Excel Discussion (Misc queries) 1 August 4th 05 03:43 AM
In Excel 2000, How do you select the whole of a worksheet (Select. Rascal Excel Discussion (Misc queries) 1 March 5th 05 12:03 AM
In Excel 2000, How do you select the whole of a worksheet (Select. Rascal Excel Discussion (Misc queries) 1 March 4th 05 11:59 PM
Auto Select a file not knowing its specific name JeffFinnan Excel Programming 0 August 1st 03 12:57 PM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"