Home All Groups Group Topic Archive Search About

Select * from Excel WorkSheet

Author
13 May 2006 11:49 AM
Tedmond
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

Author
13 May 2006 2:08 PM
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)



Show quote
"Tedmond" <Tedm***@discussions.microsoft.com> wrote in message
news:436C6A56-3875-4A88-813E-EFE9ABBD1285@microsoft.com...
> 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
>
>
Author
15 May 2006 12:37 PM
sreejith
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

Show quote
"Tedmond" wrote:

> 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
>
>
Author
15 May 2006 3:50 PM
Paul Clement
On Sat, 13 May 2006 04:49:01 -0700, Tedmond <Tedm***@discussions.microsoft.com> wrote:

¤ 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)

AddThis Social Bookmark Button