Warning upon closing sheet

  • Thread starter Thread starter stevieboy1313
  • Start date Start date
S

stevieboy1313

I have read some suggestions for a pop-up box when opening a sheet, but how
can I create a message box that appears when you close the worksheet? Any
help will be appreciated.
 
Hi,

Right click the sheet tab, double click the appropriate sheet and paste this
in.

Private Sub Worksheet_Deactivate()
MsgBox "Your closing thid sheet!!"
End Sub

Mike
 
Hi,

I should have said, Right click the sheet tab, view code, double click the
appropriate sheet and paste the code in.

Mike
 
Put this macro in the workbook code area:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox ("YOU HAVE BEEN WARNED!!!!")
End Sub
 
Thank you very much folks, but I couldn't get it to work. The sheet just
closed like always.
 
Hi,

If you followed the guidance for instaling the macro and I suggest you
re-read and try again and it still doesn't work then macros may be disabled
so try enabling them

Mike
 
Right-click on the Excel Icon left of "File" on the menubar.

Select "View Code" and paste G'sS's code into that module.

Do not place it in a sheet module as Mike suggested.

Workbook_BeforeClose events do not run from worksheets but Mike may have been
confused by your referring to a workbook as a "worksheet"

Workbooks can contain one or more worksheets. You cannot "close" or "open" a
worksheet.

You can however "deactivate" or "activate" worksheets and run sheet event code.


Gord Dibben MS Excel MVP
 
Back
Top