Preventing Users from Modifying Custom Command BarsThis content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
There might be circumstances when you want to make sure that users of your custom application cannot delete or disable your custom command bars by using the Customize dialog box. The easiest, but least secure, way to keep users from modifying your custom command bars is to disable the command bars and make sure they are visible only when absolutely necessary. You disable a command bar by setting its Enabled property to False. You hide a command bar by setting its Visible property to False. However, hiding a command bar does nothing to prevent users from getting to the bar through the Customize dialog box.
To completely restrict access to your custom command bars, you must restrict all access to the Customize dialog box. This dialog box can be accessed in three ways: by pointing to Toolbars on the View menu and then clicking Customize; by right-clicking any command bar and then clicking Customize on the shortcut menu; and by clicking Customize on the Tools menu.
All Microsoft® Office applications use the Toolbar List pop-up command bar to provide access to built-in and custom command bars. The Toolbar List command bar appears when you click Toolbars on the View menu or when you right-click any command bar. If you set the Enabled property of the Toolbar List command bar to False as shown in the following line of code, a user will not be able to open the Customize dialog box from either of these access points:
CommandBars("Toolbar List").Enabled = False
Note Because of the way the Toolbar List command bar is constructed, you cannot disable any of its commands. The only way to disable commands on this command bar is to disable the entire command bar.
Because you also can open the Customize dialog box by clicking Customize on the Tools menu, you will have to disable this command as well to completely restrict access to your custom command bars. The following procedure illustrates how to disable all access to the Customize dialog box:
Sub AllowCommandBarCustomization(blnAllowEnabled As Boolean) ' This procedure allows or prevents access to the command bars ' Customize dialog box according to the value of the blnAllowEnabled ' argument. CommandBars("Tools").Controls("Customize...").Enabled = blnAllowEnabled CommandBars("Toolbar List").Enabled = blnAllowEnabled End Sub
Working with Command Bars | Manipulating Command Bars and Command Bar Controls with VBA Code | Getting Information About Command Bars and Controls | Creating a Command Bar | Hiding and Showing a Command Bar | Copying a Command Bar | Deleting a Command Bar | Working with Personalized Menus | Working with Images on Command Bar Buttons | Working with Command Bar Controls | Working with Command Bar Events