Warning upon closing sheet

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.
 
M

Mike H

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
 
M

Mike H

Hi,

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

Mike
 
G

Gary''s Student

Put this macro in the workbook code area:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox ("YOU HAVE BEEN WARNED!!!!")
End Sub
 
S

stevieboy1313

Thank you very much folks, but I couldn't get it to work. The sheet just
closed like always.
 
M

Mike H

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
 
G

Gord Dibben

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
 

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