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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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 ???...(y)....I have 'em all the time !!!
 
Upvote 0

Forum statistics

Threads
1,215,688
Messages
6,126,210
Members
449,299
Latest member
KatieTrev

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