Microsoft Office 2000/Visual Basic Programmer's Guide |
There may be circumstances when you want to make sure that users of your custom solution can’t 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 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 can also open the Customize dialog box by clicking Customize on the Tools menu, you will need to disable this command as well in order 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
The AllowCommandBarCustomization procedure is available in the modCommandBarCode module in CommandBarSamples.mdb in the Samples\CH06 subfolder on the companion CD-ROM.