You are on page 1of 3

http://quicktestprofessional.wordpress.

com/category/excel-automation/

But incase you wish to read Excel values into your script, try this.... dim dim dim dim sExcelObj sWorkBook sWorkSheets sValue

set sExcelObj = CreateObject("Excel.Application") sExcelObj.Visible = true set sWorkBook = sExcelObj.Workbooks.Open ("path of file") set sWorkSheets = sWorkBook.ActiveWorkbook.worksheets ("sheetname") sValue = sWorkSheets.cells(row,col).value You can also create an array to continously loop through your excel sheet and re ad all required values. ******************************************************************************** ************* To add a sheet datatable.addsheet("sheetname") To import sheet datatable.importsheet "c:\excelfile.xls", "sheet1" To get a value form excel file.. Empno = datatable.value("empno", "sheet1") To run the script for all the iterations.. For i = 1 to datatable.getsheet("sheet1").getrowcount msgbox datatable.value("empno", "sheet1") Next OR For i = 1 to datatable.getrowcount datatable.setcurrentrow(i) datatable.getcurrentrow msgbox datatable.value("empno", "sheet1") datatable.setnextrow Next ******************************************************************************** ****** Re: How to Import the data from MS-Excel in QTP? Hi boss the mentioned code is a sample code. just modify it according ur requirement s. ============================================================

testSheetPath = 'address off the sheet testSheetName = 'name of the sheet columnno = 1 'In excel sheet you are selecting A1 cell For start =1 to end 'Starting from 1st cell to end point start = start+1 'incrementation for i = 1 to rowscount Set objWorkbook = objExcel.WorkBooks.Open("path of the file.xls") Set objDriverSheet = objWorkbook.Worksheets("name of the sheet") columncount = objDriverSheet.usedrange.columns.count rowcount = objDriverSheet.usedrange.rows.count for i = 1 to colunmcount columnname = objDriversheet.cells(i,1) if columnname = knowncolumnname then for j = 1 to rowcount fieldvalue = objdriversheet.cells(j,i) next next next end if next For each element in arrField 'for statement to retrieve the value arrFieldNameAndValue = split(element,";",-1) strFieldName = arrFieldNameAndValue(0) strFieldValue = arrFieldNameAndValue(1) strFieldName = removespace(lcase(strFieldName)) 'removing all the spaces Select Case strFieldName Case "Cellvalue" strcellvalue = strFieldValue Case " " end select next ******************************************************************************** ********* 1: Function ParamValues(InputFilePath,SheetName) 2: Dim input() 3: Set appExcel = CreateObject( Excel.Application ) Step 1 4: Set objWorkBook = appExcel.Workbooks.Open (InputFilePath) Step 2 5: Set objSheet = appExcel.Sheets(SheetName) Step 3 6: For i=2 to 50 Step 4 7: if objSheet.cells(i,1).value <> then 8: Input(i-2)=Trim(objSheet.cells(i,1).value) 9: else 10: Exit For 11: End If 14: Next 15: 16: 17: 18: appExcel.quit Step 5 Set appExcel=Nothing Step 6 Set objSheet=Nothing Set objWorkBook=Nothing

19: End Function

******************************************************************************** *************