BeforeClose Procedure not working

hyoung3

New Member
Joined
May 9, 2011
Messages
21
Hi,
I am having trouble using the Workbooks_BeforeClose procedure in excel. Macros seems to be enabled because in order the use the spreadsheet the user must click a button with a macro assigned to it. Unfortunately, when the workbook is closed and reopened to procedure I assigned to the close never executes. Here is the code:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    

    Sheets("Prospects").Select
    Sheets("Welcome Page").Visible = True
    Application.Run "BLPLinkReset"
    Sheets("Prospects").Select
    Application.Run "BLPLinkReset"
    Sheets("Prospects").Select
    ActiveWindow.SelectedSheets.Visible = False
    Application.Run "BLPLinkReset"
    ActiveWorkbook.Protect Password:="Password", Structure:=True, Windows:=False
    ActiveWorkbook.Save

End Sub

Why is this not executing?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Welcome to the Board!

Have you tried putting a breakpoint on the first line and stepping through the code?
 
Upvote 0
Yes. So I put a break point on the line "Sheets("Prospects").Select" and closed the workbook, but it closed without even stopping the procedure. I am kinda new to debugging so maybe I am going about it the wrong way.
 
Upvote 0
Sounds like you may have disabled Events, because the debugger stops for me.

In the Immediate window type:

?Application.EnableEvents

And hit enter. If it comes back False, you need to set it to True.
 
Upvote 0
Ok, yes, it came back false. But where do I place the "application.EnableEvents = True" code? Also, just so I get an understanding about how to troubleshoot this in the future how did I disable events?
 
Upvote 0
Just type:

Application.EnableEvents = True in the Immediate Window and hit enter. That will reset it.

To see where you might have disabled events, I'd do a procedure search for "EnableEvents".
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

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