ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I set the worksheet to save before closing? (https://www.excelbanter.com/excel-discussion-misc-queries/33934-how-do-i-set-worksheet-save-before-closing.html)

kodaco

How do I set the worksheet to save before closing?
 
When there is a change in a worksheet and I try to close it, a message asks
me whether I want to save the worksheet or not? How do I turn on this
notification before closing the sheet?

Anne Troy

Open your workbook. Hit Alt+F11 or Tools--Macro--Visual basic editor
(VBE). On the left, double-click ThisWorkbook. Paste the following code into
the ThisWorkbook code window. Hit the Save diskette at top-left. Close the
VBE. Make a change to the workbook, and close it to test. Was the change
saved? Should be. :)

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.Save

End Sub

*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com


"kodaco" wrote in message
...
When there is a change in a worksheet and I try to close it, a message

asks
me whether I want to save the worksheet or not? How do I turn on this
notification before closing the sheet?





All times are GMT +1. The time now is 10:54 AM.

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