Posted to microsoft.public.excel,microsoft.public.excel.interopoledde,microsoft.public.excel.programming,microsoft.public.excel.sdk
|
|
Retrieving list of worksheets programmatically
For Each sh In Workbooks("My_Worksheet.xls").Worksheets
Debug.Print sh.Name
Next sh
The workbook in question needs to be open.
--
HTH
Bob Phillips
"Scott Bass" <usenet739_yahoo_com_au wrote in message
...
Hi,
Sorry if this is a FAQ. I did search a number of Excel newsgroups and
Google hits before posting.
Say I have an Excel spreadsheet C:\Temp\My_Worksheet.xls, and it contains
the worksheets "Foo", "Bar", and "Foo Bar". Is there a simple script I
can
write that will retrieve the names of the worksheets?
Something like:
VB:
wscript GetWorksheetNames.vbs "C:\Temp\My_Worksheet.xls"
C#:
GetWorksheetNames.exe "C:\Temp\My_Worksheet.xls"
In both cases, it would return:
Foo
Bar
Foo Bar
to stdout.
I'd like it to be as fast and efficient as possible, so would prefer an
..exe
over a script if possible. However, I'm a novice with VB and C#
programming, but otherwise an OK programmer.
FYI, this is just to integrate the Excel data with another language (SAS).
SAS can import Excel data automatically, but cannot determine the name of
the worksheets; you have to hardcode the worksheet names. If I can write
some code that queries the spreadsheet for its worksheet names, I can use
that as "glue" to build the proper syntax in SAS to import the Excel data.
So, I don't need to get at the data itself, just the worksheet names.
Thanks for any input you can provide.
Regards,
Scott
|