Link to home
Start Free TrialLog in
Avatar of Justin
Justin

asked on

Excel file that does not ask to be saved before exiting

Hi Guys, I update an Excel file everyday but for some reason it does not ask whether I need to save when I am exiting the spreadsheet and I lose my data as a result sometimes. Is there an Excel setting I can change to remind me to do this?
Avatar of Shums Faruk
Shums Faruk
Flag of India image

You can add below code in your Workbook module:
Private Sub Workbook_BeforeClose(Cancel As Boolean) 
    Dim answer As String 
    Dim question As String 
    question = "have you completed all the fields in the workbook" 
    answer = MsgBox(question, vbYesNo) 
     
    If answer = vbNo Then 
        MsgBox "complete everything and then close" 
        Cancel = True 
        Exit Sub 
    Else 
        ThisWorkbook.Save 
    End If 
End Sub 

Open in new window

Like below image;
User generated image
Avatar of Bill Prew
Bill Prew

If you made changes to the file then it should always ask if you want to save on exit.  Are there any macros in the file that could be causing a problem?

~bp
ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Justin

ASKER

SUPERB
Pleasure Sir! Glad I was able to help