Saturday, May 10, 2014

VBSCRIPT to find Used rows & columns of Excel

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.usedrange.rows.count 'count no of used rows
          nc=ows.usedrange.columns.count 'count no of used columns
         print("nc "&nc) 'display no of columns
         print("nr "&nr) 'displya no of rows
              oex.Quit 'close excel application
'destry 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