或者先检测文件是否存在 if dir("c:\123.xls")<>0 then kill c:\123.xls
On Error Resume Next dbNamePath = txtOutPutPath & "\" & WorkBookName If Dir(dbNamePath) = WorkBookName Then Kill (dbNamePath) If Err.Number <> 0 Then Call MsgBox(WorkBookName & "error ", vbInformation) Exit Sub End If End If On Error GoTo Exit_Err Workbook.SaveAs txtOutPutPath & "\" & WorkBookName Workbook.Close True
if dir("c:\123.xls")<>0 then kill c:\123.xls
dbNamePath = txtOutPutPath & "\" & WorkBookName
If Dir(dbNamePath) = WorkBookName Then
Kill (dbNamePath)
If Err.Number <> 0 Then
Call MsgBox(WorkBookName & "error ", vbInformation)
Exit Sub
End If
End If On Error GoTo Exit_Err Workbook.SaveAs txtOutPutPath & "\" & WorkBookName
Workbook.Close True