Wednesday, 29 January 2014

Adding Columns in Excel Using QTP

The below program is used to add coloum values using QTP tool, VBScript Discriptive Language and Excel

1. Create an excel file with first four columns and six rows, give some values
2. Add the four column values and show the results in fifth column
3. Save and Close the excel file

Option explicit
Dim exo, wbo, wso, nor, i, a, b, c, d,T
'open excel file sheet using VBScriptSet exo=createobject("excel.application")
Set wbo=exo.workbooks.open("C:\Documents and Settings\qa\Desktop\QTP Practice\PATH FILES\Addition.xls")
Set wso=wbo.worksheets("sheet1")
Nor= wso.usedrange.rows.count
Exo.visible=true
'perform reading and writing from the excel file using VBScript
For i = 2 to nor step 1
a=wso.cells (i,1)  '(Reading)
b=wso.cells (i,2)
c=wso.cells (i,3)
d=wso.cells (i,4)  '(Reading)
T=cint(a)+cint(b)+cint(c)+cint(d)
Wso.cells(i,5)=T  '(Writing)
Next
'Save excel file and close application
Wbo.save
Exo.quit
Set wso=nothing
Set wbo=nothing
Set exo=nothing

No comments:

Post a Comment