"Scott Bass" <usenet739_yahoo_com_au wrote in message
...
Thanks Bob, I appreciate the reply.
I've trolled around on Google some more, and this is what I've got so far:
Option Explicit
Dim filePath, oExcel, oSheet, sheetName
filePath = WScript.Arguments(0)
Set oExcel = CreateObject("Excel.Application")
oExcel.Workbooks.Open(filepath)
Set oSheet = oExcel.ActiveWorkbook.Worksheets(1)
sheetName = oSheet.Name
Dim StdIn, StdOut
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
StdOut.WriteLine (sheetName)
oExcel.ActiveWorkbook.Save
oExcel.ActiveWorkbook.Close
set oSheet = Nothing
Set oExcel = Nothing
Can someone help me wrap this in a loop? In pseudocode:
Do i=1 to <number of worksheets
Set oSheet = oExcel.ActiveWorkbook.Worksheets(i)
sheetName = oSheet.Name
StdOut.WriteLine (sheetName)
Loop ' end loop
It's almost done.
For i = 1 To oExcel.ActiveWorkbook.Worksheets.Count
Set oSheet = oExcel.ActiveWorkbook.Worksheets(i)
sheetName = oSheet.Name
StdOut.WriteLine (sheetName)
Next i
Like I said, I don't know VB, so if you want to provide error checking for
missing argument and argument file doesn't exist, that would be fantastic.
Lastly, can I plug the code into VisualStudio .Net and create an EXE for
this?
No idea, don't do .Net
[Slightly off topic: I have to invoke this as:
cscript //B getWorksheetNames.vbs C:\Temp\test.xls
What's the difference between wscript and cscript? It took me a while to
discover that the above barfs in wscript (the default) but works in
cscript.
Why are there two scripting engines?]
There aren't. cscript.exe is a console application that runs inside an
MS-DOS box, whereas wscript.exe is a windows application.As I understand,
there are no specific differences between them, they are just targeted at
different platforms.