Dim xapp As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet Set wb = xapp.Workbooks.Open(“Excel文件路径”)
Set ws = wb.Worksheets(“工作表索引号”)
ws.Activatews.Cells(2, 4).Select ‘这个就是D2单元格,选中
Selection.EntireRow.Delete '选中D2所在的行,删除 wb.Save
wb.Close (True)
xapp.Quit
Set ws = Nothing
Set wb = Nothing
选中最左边纵向的数字鼠标右键删除该行即可
Rows(2).Delete
或者:
range("A2").entirerow.delete
代码及注释如下:
sub main()
Dim ap As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet Set wb = ap.Workbooks.Open(“D:\123.xls”)'打开工作簿
Set ws = wb.Worksheets(“Sheet1”)'赋值工作表
ws.Activatews.Cells(2, 4).Select '选中D2所在单元格
Selection.EntireRow.Delete '选中D2所在的行,然后执行删除行
wb.save‘保存工作表
wb.close'关闭工作表
ap.Quit'退出Excel程序
Set ws = Nothing
Set wb = Nothing
end sub