Workbook_BeforeClose event does not execute

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
Hi
My Workbook_BeforeClose event does not execute

I wanted my workbook to calculated before it closes

I put in the message box just to see if it would display. It does not

and it does not call calcbook

I have it on ThisWorkbook

I am working with excel 2007, is there and option I need to activate?

Thanks
L

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.EnableEvents = True

Sheets("Data").Select
ActiveSheet.Calculate
Application.Calculation = xlAutomatic
Application.CalculateBeforeSave = True

Call CalcBook

MsgBox ("HELLO")


End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
What is the value of Application.EnableEvents when you are bound to close the file? Does the event itself fire?
 
Upvote 0
No, I had turned them off earlier, so I was putting them back on. But you are correct they don't have to be there. But I don't even think the code executes to that point. When I close the workbook it immediatley asks if you want to save the changes. Then closes

L
 
Upvote 0
But I don't even think the code executes to that point.

A simple MsgBox or Debug.Print right after "Private Sub Workbook_BeforeClose(Cancel As Boolean)" will give you that information.

Where do put the code?

Please use code tags when you post code to the Board, thanks.
 
Upvote 0
Did you do the MsgBox or Debug.Print?
 
Upvote 0
If you turned the events off earlier, did you turn them back on? If not, the event won't work.
 
Upvote 0
Thanks Rorya That was exactly the problem

L

Hmmm, but you wrote earlier that you turned them on again?

No, I had turned them off earlier, so I was putting them back on. But you are correct they don't have to be there. But I don't even think the code executes to that point. When I close the workbook it immediatley asks if you want to save the changes. Then closes

L
 
Upvote 0
Yes, but turning them on in the BeforeClose event, which wasn't firing because events were off. ;)
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top