Automatically perform action when closing Excel Worksheet

P

PaddyMac

I want a message box to come up when I close an Excel worksheet

In the "This Workbook" module I have inserted the following code

Private Sub Workbook_Close()

MsgBox "This Worksheet is now closing"

End Sub

When I click on F5 in Visual Basic Editor, it works, but when I close the
document, it doesn't.

Any ideas?

Many thanks

Kindest regards

PaddyMac
 
J

Jacob Skaria

Double click 'This Workbook' and see the drop downs on the right code module
to see the workbook events...

'Remove your code and copy paste the below and try
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "This Worksheet is now closing"
End Sub

If this post helps click Yes
 
F

FSt1

hi.
there isn't a workbook_close event. there is a workbook_beforeclose event
change the sub title to Sub WorkBook_BeforeClose(Cancel As Boolean)

regards
FSt1
 

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