Consulting

Results 1 to 5 of 5

Thread: Retreiving tab name

  1. #1

    Retreiving tab name

    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
    [VBA]
    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
    [/VBA]
    Though, everything is registering as a Hit? It should be 31 misses, and 1 hit

    Any ideas?
    Thank you!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why loop through them, why not address the target sheet directly?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    And in your code, shouldn't

    [vba]

    activeSheetName = objExcel.ActiveSheet.Name
    [/vba]

    be

    [vba]

    activeSheetName = currentWorkSheet.Name
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Quote Originally Posted by xld
    And in your code, shouldn't

    [vba]

    activeSheetName = objExcel.ActiveSheet.Name
    [/vba]
    be

    [vba]

    activeSheetName = currentWorkSheet.Name
    [/vba]
    That did it
    thank you.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    But as I said, why not address it directly? Cut out the loop.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •