workbook_open() & workbook_beforeclose()

Fwiz

Board Regular
Joined
May 15, 2007
Messages
241
i'm tryin to add in this 2 vba codes - the first to workbook open event and the second is to workbook before close event

Sub workbook_open()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=522)
Ctrl.Enabled = False
Next Ctrl
End Sub

Sub workbook_beforeclose()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=522)
Ctrl.Enabled = True
Next Ctrl
End Sub

i can't seem to make the vba code work correctly when opening and closing the workbook.
- am i missing something?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Fwiz, Have you placed the code in the "ThisWorkbook" object area? Given that the workbook_open() has no capitals I suspect not.
 
Upvote 0
Fwiz, Have you placed the code in the "ThisWorkbook" object area? Given that the workbook_open() has no capitals I suspect not.

dont know if it's relevant, but I noticed that the Before_close doesnt have the 'Cancel As Boolean' parameter
 
Upvote 0
ahhhh see, newby mistakes!!!
i've added this to the workbook module area and added cancel as boolean....all sorted

thanks for your input guys!!
 
Upvote 0

Forum statistics

Threads
1,222,146
Messages
6,164,231
Members
451,881
Latest member
John kaiser

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