Workbook_BeforeClose (Cancel As Boolean)

rob_sheeds

Board Regular
Joined
Dec 9, 2010
Messages
57
Hi, I have read all there is in here on the Workbook_BeforeClose and I cant get it to work. The jist is to protect all sheets and the workbook whenever a user closes the workbook.
Current code is (which is under ThisWorkbook). Any help would be excellent and thanks in advance.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Call ProtectAllSheets

End Sub

Sub ProtectAllSheets()
'Protects ALL worksheets
For Each Shts In ThisWorkbook.Worksheets
Shts.Protect Password:="evo!@#"
Next
ActiveWorkbook.Protect Password:="evo!@#"
End Sub
 
in the private workbook_beforeclose subroutine, put the following lines, in that order.

Call ProtectAllSheets
ThisWorkbook.Close SaveChanges:=True

need to be in that order. Also make sure designer mode is disabled. I tested it with designer mode on and got a dialog box when closing, so that might be an issue.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Nerrr the code was not in ThisWorkbook.... my bad guys. Im an accountant not a guru like you all.
Appreciate your help as always!!!!!!!
 
Upvote 0
Hmm....Seniors moment ???...:beerchug:....I have 'em all the time !!!
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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