Count number of tabs in Excel with UFT
Question ID: 107724
0
0

I’m using UFT to compare to Excel workbooks. I need to count the number of tabs in each worksheet. Using ‘excelObj.WorkbookName.Sheets.Count’ is returning more tabs than the number of tabs that are there. Is it counting deleted tabs or something?

Marked as spam
Posted by (Questions: 227, Answers: 22)
Asked on July 18, 2017 5:13 pm
240 views
Answers (1)
0
Private answer

It's probably seeing hidden tabs that exist in the workbook. Here's a sample of some code that you can use that will count the number of visible and hidden tabs so you can see a count of each. You can take the code a step further and use the visible count variable in your script for the value of the number of visible tabs displayed and this should return the correct number you want:

For i = 1 To excelObj.WorkbookName.Sheets.Count
visibleCount=0
invisibleCount=0
If Not excelObj.WorkbookName.Sheets(i).Visible Then
invisibleCount=invisibleCount+1
Else
visibleCount=visibleCount+1
End If
Next

MsgBox ''Visible Tabs Count: ''& visibleCount & '' Invisible Tabs Count: ''& invisibleCount

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on July 18, 2017 5:17 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top