Event after "Save changes?" prompt when exiting

  • Thread starter Thread starter robotman
  • Start date Start date
R

robotman

I am trying to run a piece of code as the very last thing Excel does
when a workbook is closed.

I can use the Workbook_BeforeClose event, but this event is triggered
BEFORE Excel asks the user if they want to save any changes.

Is there any way to catch the final close event or maybe manually
detect and prompt for "Save changes?" in the BeforeClose event before
executing my final code?

Thanks.

John
 
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFile
Application.EnableEvents = False
'<Optional - this would be before save code>
Cancel = True
If SaveAsUI Then
sFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If sFile <> False Then
ThisWorkbook.SaveAs sFile
'<Optional - this would be after save code>
End If
Else
ThisWorkbook.Save
'<Optional - this would be after save code>
End If
Application.EnableEvents = True
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Back
Top