Clean up Excel Sheet Using Vb Script
Public Function ExcelFileCleanup(fileName)
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Visible = false
ExcelObj.DisplayAlerts = False
ExcelObj.Workbooks.Open(fileName)
RowC = ExcelObj.ActiveSheet.UsedRange.Rows.Count
If RowC >= 2 Then
' Note: row 1 in Excel file is the column header in the data table
' To delete row 2 of the data table is to delete row 3 in an Excel file
ExcelObj.Rows("2:" &RowC).Select
ExcelObj.Selection.Delete
End If
ExcelObj.ActiveWorkbook.Save
ExcelObj.Quit
' Release created Objects
Set ExcelObj = Nothing
End Function
Public Function ExcelFileCleanup(fileName)
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Visible = false
ExcelObj.DisplayAlerts = False
ExcelObj.Workbooks.Open(fileName)
RowC = ExcelObj.ActiveSheet.UsedRange.Rows.Count
If RowC >= 2 Then
' Note: row 1 in Excel file is the column header in the data table
' To delete row 2 of the data table is to delete row 3 in an Excel file
ExcelObj.Rows("2:" &RowC).Select
ExcelObj.Selection.Delete
End If
ExcelObj.ActiveWorkbook.Save
ExcelObj.Quit
' Release created Objects
Set ExcelObj = Nothing
End Function
No comments:
Post a Comment