Before Close Workbook Event

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have some code in a Before Close sub which concludes with
VBA Code:
ActiveWorkbook.Close SaveChanges:=True

I've also got some code in a Before Save sub - does that line of code force the Before Save routine to run?

I want to keep the code above but don't want to call the Before Save sub, I only want that called if the user hits the save icon.

Any thoughts appreciated.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Wrap that line as below:
VBA Code:
Application.EnableEvents = False
ActiveWorkbook.Close SaveChanges:=True
Application.EnableEvents = True

The 'Application.EnableEvents = False' prevents the code that is being run in between from firing other events.

VBA Code:
Application.EnableEvents = False
' code where you do not want to fire events
Application.EnableEvents = True
 
Upvote 0
Solution
I say no, so no additional code needed. then again, I did limited testing. If you want to know how to test such things, put break points in your code and step through.
 
Upvote 0
I say no, so no additional code needed. then again, I did limited testing. If you want to know how to test such things, put break points in your code and step through.
How do you step through a Before Close sub? I tried with F8 but nothing gets highlighted in yellow to indicate the trace has started.
 
Upvote 0
In my testing i found that:
VBA Code:
ActiveWorkbook.Close SaveChanges:=True
Fired the before save event, i tested it by placing msgboxes as i am old schooool lol
 
Upvote 0
How do you step through a Before Close sub? I tried with F8 but nothing gets highlighted in yellow to indicate the trace has started.
I usually place a breakpoint at the first line of code inside of the procedure.
Then, when it enters into that code naturally, it will stop there, and then you can use F8 to step through the rest of the code.
 
Upvote 0
I put a break point at the start of the close event and followed it through and the save event didn't fire. However, I invoked close from the immediate window like
application.close

I just tried again but this time used the upper right close button. This time, it did fire.
Don't know what I'm on about, I guess. :unsure:
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,326
Members
448,564
Latest member
ED38

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