ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Event after "Save changes?" prompt when exiting (https://www.excelbanter.com/excel-programming/390914-event-after-save-changes-prompt-when-exiting.html)

robotman

Event after "Save changes?" prompt when exiting
 
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


Bob Phillips

Event after "Save changes?" prompt when exiting
 
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)



"robotman" wrote in message
oups.com...
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





All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com