2个回答
展开全部
'菜单“工程/引用”,勾选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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询