The Workbook.BeforeClose event triggers when the workbook is about to close but before the saving message prompt which allows cancelling it.
How can I detect when the wo
This post could be helpful https://www.dummies.com/software/microsoft-office/excel/an-excel-macro-to-save-a-workbook-before-closing/
I found code below from the book Excel 2016 Power Programming with VBA, by Michael Alexander
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim msg As String, ans as integer If Me.Saved = False Then msg = "Do you want to save?" ans = MsgBox(msg, vbquestion+vbyesnocancel) Select Case ans Case vbYes: Me.Save Case vbCancel: Cancel = True End Select End If Call mySub Me.Saved = True End Sub