用vb删除excel的某一行具体程序

本人是初学者,可不可以给出具体代码

'菜单“工程/引用”,勾选Microsoft Excel 11库,必须的
Private Sub Command1_Click()

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then Set xlApp = CreateObject("Excel.Application")
On Error GoTo prcERR
Set xlBook = xlApp.Workbooks.Open(App.Path & "\test.xls") '打开你的EXCEL文件
Set xlSheet = xlBook.Worksheets(1)'第一个表格
xlSheet.Application.Visible = True '设置Excel 可见
xlSheet.Rows("1:1").Delete Shift:=xlUp'假如要删除第1行。删除第2行就是"2:2",删除1-3行就是"1:3"
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Exit Sub
prcERR:
Debug.Print Err.Number & ":" & Err.Description
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-14
比如要删除第5行,代码如下:
Sub Macro1()
Rows("5:5").Select
Selection.ClearContents
End Sub追问

本人是初学者,可不可以给出具体代码