Micro Focus QTP (UFT) Forums
importing excel file and run on all iterations - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: importing excel file and run on all iterations (/Thread-importing-excel-file-and-run-on-all-iterations)



importing excel file and run on all iterations - vineet.k - 05-21-2011

hi,
a) i want to know how to import data from external excel sheet and run the flight application with single login name in global sheet and create order for 3 different users i.e for 3 different user names from excel sheet.
b)Then same for 3 different login users.

In 1st case i am not able to run for all 3 rows for single login but it is running for 1st row 3times ...So i want to know how to run for all iterations?


RE: importing excel file and run on all iterations - Anand - 05-23-2011

i think u r not incrementing the counter of row number. Try this.. but dont increment column value

suppose col1 contains user name and col2 contains password
-------------------------------------------
Code:
dim sExcelObj
dim sWorkBook
dim sWorkSheets
dim sValue

set sExcelObj = CreateObject("Excel.Application")
sExcelObj.Visible = true
set sWorkBook = sExcelObj.Workbooks.Open ("path of file")
set sWorkSheets = sWorkBook.ActiveWorkbook.worksheets ("sheetname")

username = sWorkSheets.cells(row,col1).value
password= sWorkSheets.cells(row,col2).value
row=row+1

You can also import your excel into QTP and then iterate. also you need to do some setting in options. Check the file attached.
----------------


Code:
datatable.importsheet "c:\excelfile.xls", "sheet1"

To get a value form excel file..
Code:
Empno = datatable.value("empno", "sheet1")

To run the script for all the iterations..
Code:
For i = 1 to datatable.getsheet("sheet1").getrowcount
msgbox datatable.value("empno", "sheet1")
Next