Select * from Excel WorkSheet

G

Guest

Hi all,

I know I can select data from a Excel worksheet using the following command
text.

"Select * From [Sheet1$]"

That is ok for the worksheet using default name "Sheet1". But, how can I
select data from a wroksheet that I don't know it's name. Can I use somthing
like

"Select * From Sheet[0]"

Of course, the above doesn't work. Can anyone tell me how to do it?

Thanks for any help!

Tedmond
 
S

Scott M.

If you are using the Excel Object Library, you can refer to a sheet in
several ways:

The sheet Name (Sheet1)
Via the sheets collection (Sheets(n) or Sheets("sheetName"))
The current sheet (ActiveSheet)
 
G

Guest

hi,

u can use some thing like this

"select * from [" & strShetname & "$]"

where "strShetname " is the name of the sheet.Please note that you can take
the
name of the sheet from active sheet
like this
Dim oApp As New Excel.Application
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add(fileName)
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet()
strShetname = oSheet.Name

hope it will solve ur problem..

thnaks

sreejith
 
P

Paul Clement

¤ Hi all,
¤
¤ I know I can select data from a Excel worksheet using the following command
¤ text.
¤
¤ "Select * From [Sheet1$]"
¤
¤ That is ok for the worksheet using default name "Sheet1". But, how can I
¤ select data from a wroksheet that I don't know it's name. Can I use somthing
¤ like
¤
¤ "Select * From Sheet[0]"
¤
¤ Of course, the above doesn't work. Can anyone tell me how to do it?
¤

Recently posted a couple of times:

http://tinyurl.com/ze36t


Paul
~~~~
Microsoft MVP (Visual Basic)
 

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