Save Changes

If you want to make sure that all changes are saved when the workbook closes, but you don't want the user to be prompted to save changes, you can save the workbook in the BeforeClose event procedure. You can check to see if this is really necessary using the Saved property of the workbook, which will be False if there are unsaved changes:

Private Sub Workbook_BeforeClose(Cancel As Boolean) If Not ThisWorkbook.Saved Then

ThisWorkbook.Save End If End Sub

If, on the other hand, you want to discard any changes to the workbook, and you don't want users to be prompted to save changes in a workbook when they close it, you can set the Saved property of the workbook to True in the BeforeClose event procedure:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Saved = True End Sub

This fools Excel into thinking that any changes have been saved.

0 0

Post a comment