Saving VBA project on workbook close

G

Guest

Sorry if this is an obvious one. I want to have code to protect myself from
closing a project without saving changes. The code below just doesn't execute
the save although the logic hits the line.

TIA, Eric

in Thisworkbook

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = Not Shutdown(ThisWorkbook)
If Cancel Then
Call ThisWorkbook.Save
Debug.Assert ThisWorkbook.Saved
Cancel = False
End If
End Sub
 
C

Corey

Sub Macro1()
Application.DisplayAlerts = True
ActiveWorkbook.Save ' saves active workbook
Application.Quit ' exits Excel
End Sub


Corey....
 
N

NickHK

You need to provide more details if you want constructive help.
What are supposed to make of "Doesn't work for me" ?

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top