Wednesday, May 4, 2011

QTP-Import Data from Excel using Excel Object in QTP without using datatable

Hi Folks,

I try to write article on how to use Import Excel Data using QTP with Excel object.(Without using Data table).
Hope this will helpful to you.

URL=http://www.google.com/

Systemutil.Run "iexplore.exe",URL
browsernm=".*Google.*"
Pagenm=".*Google.*"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)

Dim oexcel
Dim obook
Dim osheet
sSampleFolder="C:\"
sSampleFile="Book2.xls"

Set oexcel=CreateObject("Excel.Application")'run excel application
Set obook=oexcel.Workbooks.Open("c:\Book2.xls") 'open work book from specified location
Set osheet=obook.Worksheets(1)'open worksheet with name or index specified

rowcnt=osheet.usedrange.rows.count ' get row count in excel sheet
msgbox rowcnt

For i=1 to rowcnt
temp=osheet.cells(i,1).value
CurrObj.WebEdit("name:=q").Set temp
CurrObj.WebButton("name:=Google Search").Click
Browser("title:=.*Google.*").Back
wait(3)
Next

colcnt=osheet.usedrange.columns.count 'get column count in excel sheet
msgbox colcnt

Set osheet = Nothing
Set obook = Nothing
oexcel.Quit()
Set oexcel = Nothing

No comments:

Post a Comment