PDA

View Full Version : Retreiving tab name



onlines
01-13-2009, 09:43 AM
Basically, i want to loop through all 32 available tabs until i hit a specific tab and then work with that one.
Example. Find the tab labeled "MTD" (Month to date)

I currently have this

for counter = 1 to worksheetCount
WScript.Echo "Reading Data from worksheet " & counter & vbCRLF
Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
activeSheetName = objExcel.ActiveSheet.Name
if activeSheetName = "MTD" then
WScript.Echo "MTD Hit "
else
WScript.Echo "MTD Missed"
end if
set currentWorkSheet = Nothing
set activeSheetName = Nothing
next

Though, everything is registering as a Hit? It should be 31 misses, and 1 hit

Any ideas?
Thank you!

Bob Phillips
01-13-2009, 09:57 AM
Why loop through them, why not address the target sheet directly?

Bob Phillips
01-13-2009, 09:59 AM
And in your code, shouldn't



activeSheetName = objExcel.ActiveSheet.Name


be



activeSheetName = currentWorkSheet.Name

onlines
01-13-2009, 11:03 AM
And in your code, shouldn't



activeSheetName = objExcel.ActiveSheet.Name

be



activeSheetName = currentWorkSheet.Name


That did it
thank you.

Bob Phillips
01-13-2009, 11:23 AM
But as I said, why not address it directly? Cut out the loop.