Monday, August 30, 2010

QTP: Working with Excel Spreadsheets

Example of Code:
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.WorkBooks.Open("J:\My Documents\users.xls")
Set objDriverSheet = objWorkbook.Worksheets("users")

c = objDriverSheet.usedrange.rows.count

'We Start Looking at Number two since first row is column names
For i=2 to c
userId = objDriversheet.cells(i, 1)
If expectedUserId = userId Then
msgbox userId
End If
Next

Set objExcel = Nothing
Set objWorkbook = Nothing
Set objDriverSheet = Nothing

No comments: