Powered by: Dharamveer Saxena

Tuesday, November 24, 2009

TestComplete: To get all the sheets name in your excel workbook

To get all the sheets name from the excel file.

Sub Main

Set p = Sys.WaitProcess("EXCEL")
'this will Make sure you close any Excel work book already open
If p.Exists Then
Call p.Terminate()
End If

'This is setting the driver
Set MsExcel = Sys.OleObject("Excel.Application")

'This will open you workbook
'Specify the location of your excel file
Call MsExcel.Workbooks.Open("c:\test.xls")
MsExcel.Visible = True

'To Loop through all the sheet
for I = 1 to MsExcel.sheets.Count
'To activate the sheet
msexcel.Sheets(I).Activate
'To get the name of the active sheet
MsgBox(MsExcel.activesheet.name)
Next

End Sub

1 comment:

  1. what is a sys object? never heard of it

    ReplyDelete