|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Select * from Excel WorkSheetHi 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 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 > > 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 > > 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) |
|||||||||||||||||||||||