• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Auto Save before Close

Shazz

Member
Hi All,

I have a spreadsheet that I would like to have auto save before closing.

I have the below code, It says it is saving but when I go back into the spreadsheet it hasn't, can anyone help at all?

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    NEW_NAME = ActiveWorkbook.Name
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="Z:\STAFF HOLIDAY CHARTS" & NEW_NAME, FileFormat:=xlNormal, _
        Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
        CreateBackup:=False, ConflictResolution:=1
        Application.DisplayAlerts = True
End Sub
 
Don't worry, I have found another code that works fine.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.DisplayAlerts = False
        ActiveWorkbook.Save
    Application.DisplayAlerts = True
End Sub
 
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Application
    .DisplayAlerts = False
        If .Workbooks.Count > 1 Then
            ThisWorkbook.Close SaveChanges:=True
        Else
            ThisWorkbook.Save
            .Quit
        End If
    .DisplayAlerts = True
End With
End Sub
 
Back
Top