Open Microsoft Excel [Shee1$] where the name is NOT Sheet1

S

Sandy

I have an asp.net app that allows users to upload excel spreadsheets,
opens them, displays the data, allows manipulation and then inserts
the results into a SQL database.

It works fine as long as the name of the sheet is 'Sheet1'. Is there a
way to read Sheet1 without knowing what its' name is?

Here is what I am doing 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")

</code>

When Sheet1 has a different name this of course crashes. I could tell
people the sheet MUST be named Sheet1 but that is not my preference.
 
R

Rollin_Again

Set the name of the worksheet equal to a variable using th
Activesheet.name property. Then you can just reference the variable o
use some code to always change the name of the worksheet to Sheet1.


Rolli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top