VB保存Excel文件时,提示“文件已存在对话框”请问如何使直接覆盖?

解决方案 »

  1.   

    xlsApp.displayalerts=false'不出现提示框
      

  2.   

    或者先检测文件是否存在
    if dir("c:\123.xls")<>0 then kill c:\123.xls
      

  3.   

    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