Saturday, May 10, 2014

QTP script to Count no of rows and columns of EXCEL file

Option explicit
Dim oex,owb,ows,nr,nc

'open excel s/w
         Set oex=createobject("Excel.Application") 'create object ot excel application
        oex.Visible=true 'excel file will be visible while running

'go to excel file
 Set owb=oex.Workbooks.Open("PATH OF EXCEL FILE.xls") 'Create object to workbook

'open excel sheet.
       Set ows=owb.Worksheets("Sheet1") 'Create object to worksheet
             nr=ows.rows.count 'count no of rows
 nc=ows.columns.count 'count no of columns
 print("nc "&nc) 'display no of columns
           print("nr "&nr) 'displya no of rows
oex.Quit 'close excel application

'destroy objects
 Set ows=nothing                            'de allocate the memory of worksheet object
Set owb=nothing 'de allocate the memory of workbook object
 Set oex=nothing 'de allocate the memory of excel application object 

No comments:

Post a Comment