Wednesday, May 20, 2009

Excel COM : Delete Rows from Sheet

strDataFile = "(File Name with Full Path)"
strCurrentSheetName = "(Sheet Name or Index)"
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Workbooks.Open strDataFile

'Delete the first row always as the row gets shifted by one when the previous row is deleted.

For intRow = 1 To 3
ExcelObj.ActiveWorkbook.Worksheets (strCurrentSheetName).Rows(1).Delete
ExcelObj.ActiveWorkbook.save
Cnt = ExcelObj.ActiveWorkbook.Worksheets (strCurrentSheetName).Rows.count
Next
ExcelObj.Workbooks.Close
Set ExcelObj = nothing

No comments: