Event after "Save changes?" prompt when exiting

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
 
B

Bob Phillips

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)
 

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