Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grab excel worksheet names 1

Status
Not open for further replies.

seddies

Programmer
Aug 8, 2001
5
US
Hi,

I'm seeking some vbscript code in order to grab all the worksheet names from an excel file, anyone got any suggestions, pointers. I am able to query the actual worksheets when hard coded but how do you select the worksheets. hmmmmm........

thanks
 


seddies,

Here's some code that should work for you.

fengshui1998


Set objXL = WScript.CreateObject("EXCEL.application")
' objXL.Visible = True
Set objWkBook = objXL.WorkBooks.Open "YourExcelFile"
Set colSheets = objWkBook.Sheets
For Each Sheet In colSheets
wscript.echo Sheet.Name
Next
 
Hi Fengshui1998,

thanks for the reply, is that some VB code? I have never come across the WScript.CreateObject.

The code threw an error on the workbooks.open "form1.xls"
(my xl filename)
Expected end of statement
shoud the whole path be in there?

Set objXL = WScript.CreateObject("EXCEL.application")
' objXL.Visible = True
Set objWkBook = objXL.WorkBooks.Open ("form1.xls")
Set colSheets = objWkBook.Sheets
For Each Sheet In colSheets
wscript.echo Sheet.Name
Next

I also tried it with brackets which didn't throw an error but did not output anything.

Can you help me out? Where can I find some info on that WScript object?

thanks.






 
seddies,

For your filename, include the whole path such as
"C:\My Documents\Form1.xls". You can if you want remove Wscript from Wscript.CreateObject

Set objXL = CreateObject("EXCEL.application")


Fengshui1998

 
fengshui,

jackpot !!

Had to change the code a little for asp but all seems good.

Thanks so much for your tip.

here for anyone else who is interested is the code snip


Set objXL = CreateObject("EXCEL.application")
' objXL.Visible = True
Set objWkBook = objXL.WorkBooks.Open ("C:\localpath\form1.xls")
Set colSheets = objWkBook.Sheets
For Each Sheet In colSheets
Response.write Sheet.Name
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top