OFF97: How to Prevent Customization of Menus and Toolbars

Last reviewed: August 28, 1997
Article ID: Q170563
  • Microsoft Visual Basic for Applications included with:

    - Microsoft PowerPoint 97 for Windows, Service Release 1 - Microsoft Excel 97 for Windows, Service Release 1 - Microsoft Word 97 for Windows, Service Release 1

SUMMARY

In Microsoft Office 97, Service Release 1 (SR-1), the CommandBars object model allows you to disable the Toolbars shortcut menu. This simplifies preventing others from changing the toolbars and menus of a custom application that you develop with Microsoft Office 97.

MORE INFORMATION

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Disabling and Enabling the Toolbar Shortcut Menu

The following Visual Basic for Applications subroutine disables the Toolbar List shortcut menu:

   Sub DisableToolbarMenu()
       CommandBars("Toolbar List").Enabled = False
   End Sub

After you run this subroutine, the Toolbars command on the View menu is unavailable. Also, you cannot display a list of available toolbars by pointing to, and then right-clicking a toolbar.

The following subroutine enables the Toolbar List shortcut menu:

   Sub EnableToolbarMenu()
       CommandBars("Toolbar List").Enabled = True
   End Sub

Preventing Users from Changing Menus and Toolbars

Setting the Visible property of the Toolbar List shortcut menu does not prevent others from making changes to the menus and toolbars of a custom application. To prevent others from changing the menus and toolbars in a custom application, remove or disable the Customize option on the Tools menu and disable the Toolbar List shortcut menu.

The following sample subroutine disables the Toolbar List shortcut menu and deletes the Cutomize menu option, which prevents others from modifying the menus and toolbars in a custom application:

   Sub DisableCustomize()
        Application.CommandBars("Tools").Controls("&Customize...").Delete
        CommandBars("Toolbar List").Enabled = False
   End Sub

You can use the following subroutine to restore the Customize menu command and allow others to display the Toolbar List shortcut menu:

   Sub EnableCustomize()
       Application.CommandBars("Tools").Controls.Add _
               Type:=msoControlButton, Id:=797, Before:=13
       CommandBars("Toolbar List").Enabled = True
   End Sub

REFERENCES

For more information about customizing command bars, click the Office Assistant in the Visual Basic Editor, type "commandbars", click Search, and then click to view "Using command bars".

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office
               Program or Component


Additional query words: xlvbainfo
Keywords : IntpMenu IntpToolbr kbinterop kbprg PgmHowTo
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.