How can I make Excel prompt to save on close?
开发者_开发百科When you close Excel and you have edited your VBA code, it does not prompt you to Save. I just wrote 300 lines of code and it did not get saved.
how do I force it to prompt when closing?
It should have prompted you to save. Check you have not set SetWarnings to off somewhere in your code
You could Change the SetWarnings settings as sugested by Kevin.
But what I normally do is set all my excel projects to autosave on exit.
To do that, just add in the ThisWorbook module:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Close SaveChanges:=True
End Sub
Of course, if a user really screws up your file, and then bails, it will save it without asking, so it could be dangerous!
Add before the execution line of code:
response(msgbox("Do you want to save this copy of your file?",VByesNo,"")
if response =VBYes, then
line of code to save
Else
msgbox "File was not saved",vbOK,""
Exit Sub
End if
精彩评论