XL97: Problems When Disabling/Enabling MenusID: Q157754
|
In Microsoft Excel 97, if you run a Visual Basic for Applications macro
that attempts to disable an entire menu (the File menu, for example), the
menu is not disabled and you do not receive any error messages. The same
macro works correctly in Microsoft Excel versions 5.0 and 7.0.
The same applies if a Visual Basic for Applications macro attempts to
enable an entire menu.
This will occur if your macro uses code similar to the following to disable or enable an entire menu, respectively:
Application.MenuBars(xlWorksheet).Menus("File").Enabled = False
-or-
Application.MenuBars(xlWorksheet).Menus("File").Enabled = True
This behavior is by design of Microsoft Excel.
If a Visual Basic for Applications macro in Microsoft Excel 97 must disable or enable an entire menu, use code similar to the following in your macro, respectively:
CommandBars("File").Enabled = False
-or-
CommandBars("File").Enabled = True
In Microsoft Excel versions 5.0 and 7.0, menus are contained in menubars. For example, the File menu is contained by the "xlWorksheet" menubar. Because of this, the command to disable a particular menu requires that you refer not only to the menu, but also to the menubar that contains it. For example:
Application.MenuBars(xlWorksheet).Menus("File").Enabled = False
NOTE: Adding "Application." to the beginning of the line of code is usually
not required, but it is included here in order to provide a complete code
example.
CommandBars("File").Enabled = False
This command will work correctly in Microsoft Excel 97.
Sub WorksInExcel5And7()
Application.MenuBars(xlWorksheet).Menus("File").Enabled = False
End Sub
Sub WorksInExcel97()
CommandBars("File").Enabled = False
End Sub
Additional query words: XL97 8.00
Keywords : kbprg kbdta kbmigrate kbdtacode xlui KbVBA
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 2, 1999