How do I set the worksheet to save before closing?

G

Guest

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?
 
A

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
 

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