Thread
:
Select from first worksheet without knowing it's name
View Single Post
#
2
Posted to microsoft.public.excel.programming
Don Guillett[_4_]
external usenet poster
Posts: 2,337
Select from first worksheet without knowing it's name
try
Sheets(1).Activate
--
Don Guillett
SalesAid Software
"Roger Twomey" wrote in message
...
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.
Reply With Quote
Don Guillett[_4_]
View Public Profile
Find all posts by Don Guillett[_4_]