How to use workbook.saveas with automatic Overwrite

How to use workbook.saveas with automatic Overwrite

Asked on January 10, 2019 in Excel.
Add Comment


  • 2 Answer(s)

    Here is the best solution :

        Through neither identify the prompt set xls.DisplayAlerts = False

    This ConflictResolution is neither a true or false property, it may be xlLocalSessionChanges . However this has blank to do along displaying the Overwrite prompt.

    Set xls = CreateObject("Excel.Application")
    xls.DisplayAlerts = False
    Set wb = xls.Workbooks.Add
    fullFilePath = importFolderPath & "\" & "A.xlsx"
     
    wb.SaveAs fullFilePath, AccessMode:=xlExclusive,ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges
    wb.Close (True)
    

     

    Answered on January 10, 2019.
    Add Comment

    Delete the file it exists, previously executing SaveAs.

    If Dir("f:ull\path\with\filename.xls") <> "" Then
       Kill "f:ull\path\with\filename.xls"
    End If
    
        It is simple than setting DisplayAlerts off and on, and if DisplayAlerts remains off while code bang, In case  work with Excel in the same session, it can originator problems.

    Answered on January 10, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.