WD97: Disable System Menu Button and Keyboard Close Command

ID: Q192320


The information in this article applies to:
  • Microsoft Word 97 for Windows


SUMMARY

The following Visual Basic for Applications code will remove the Close command from the Document System menu list and the keyboard commands assigned to "DocClose" command. By making an item not visible, it is removed from the menu list and unavailable to users, whether the document is docked or windowed.


MORE INFORMATION

Microsoft provides programming examples 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. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/refguide/

Remove Menu Items

To disable the Close command or any item on the Document System menu list run the following lines of code. By making an item not visible, it is removed from the menu list and unavailable to the user, whether the document is docked or windowed on the screen.

   Sub HideMenuItems()
      CommandBars("System").Controls("&Close").Visible = False
      CommandBars("System").Controls("&Restore").Visible = False
      CommandBars("System").Controls("&Move").Visible = False
      CommandBars("System").Controls("&Size").Visible = False
      CommandBars("System").Controls("Mi&nimize").Visible = False
      CommandBars("System").Controls("Ma&ximize").Visible = False
   End sub 
NOTE: When you type the name of the menu item, you must type the name as it appears in the menu list (with no spaces and the "&" representing the "hot key").

Restore Menu items

To restore the system menu items, you must run the following macro.

NOTE: Closing and restarting Word does not restore the menu items.


   Sub RestoreMenu()
      CommandBars("System").Reset
   End sub 

Disable Keyboard Shortcut

To disable the keyboard shortcut key assigned to the DocClose macro, run the following code:


   Sub DisableKeyboard()
      CustomizationContext = NormalTemplate
      FindKey(BuildKeyCode(wdKeyW, wdKeyControl)).Disable
      FindKey(BuildKeyCode(wdKeyF4, wdKeyControl)).Disable
   End Sub 

Assign or Reset Keyboard Shortcut Keys

To assign the default values and functionality, run one of the following Visual Basic for Applications macros:

   Sub EnableKeyBoard()
      CustomizationContext = NormalTemplate

      KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF4, wdKeyControl), _
         KeyCategory:=wdKeyCategoryCommand, Command:="DocClose"

      KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyW, wdKeyControl), _
         KeyCategory:=wdKeyCategoryCommand, Command:="DocClose"
   End Sub 
-or-

   Sub Macro7()
      'Resets all keyboard key assignment to there default
      CustomizationContext = NormalTemplate
      KeyBindings.ClearAll
   End Sub 
For more information about command bars, from the Visual Basic Editor, click the Office Assistant, type Commandbars, click Search, and then click to view "Using command bars".

For more information about customizing Templates, from the Visual Basic Editor, click the Office Assistant, type CustomizationContext, click Search, and then click to view "CustomizationContext Property".

For more information about keyboard key stroke assignment, from the Visual Basic Editor, click the Office Assistant, type KeyBindings, click Search, and then click to view "KeyBindings Collection Object".

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:
Q176476 OFF: Office Assistant Not Answering Visual Basic Questions
For additional information, please see the following article in the Microsoft Knowledge Base:
Q173707 OFF97: How to Run Sample Code from Knowledge Base Articles

Additional query words: wordcon vba toolbars dialog box

Keywords : kbdta kbwordvba
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: October 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.