Public Sub SOutput() On Error GoTo Err1 CurrentDb.Execute "SELECT * INTO [Excel 8.0;DATABASE=C:\临时导出.Xls].Sheet1 FROM 表1" Exit1: Exit Sub Err1: If Err.Number = 3010 Then If MsgBox("存在同名文件,是否覆盖?", vbYesNo, "提示") = vbYes Then Kill "C:\临时导出.Xls" ''<-------- 如果这里出错,如何捕捉 Resume End If Else MsgBox Err.Description & Err.Number End If Resume Exit1 End Sub
解决方案:
Public Sub SOutput() On Error Resume Next CurrentDb.Execute "SELECT * INTO [Excel 8.0;DATABASE=C:\临时导出.Xls].Sheet1 FROM 表1" If Err.Number = 3010 Then If MsgBox("存在同名文件,是否覆盖?", vbYesNo, "提示") = vbYes Then
Kill "C:\临时导出.Xls" If Err.Number = 70 Then MsgBox "请关闭对象再进行操作", vbInformation, "提示" Exit Sub End If End If Else MsgBox Err.Description & Err.Number End If End Sub