Placing your menu code

Most of the time you want your menu changes to be in effect only when a particular workbook is open. Therefore, you need VBA code to modify the menu when the workbook is opened and more VBA code to return the menus to normal when the workbook is closed. A good place for your menu-manipulating code: in the code window for the ThisWorkbook object. More specifically, you use the following two event-handler procedures, which you can find out more about in Chapter 11:

i Sub Workbook_Open( )

i Sub Workbook_BeforeClose(Cancel As Boolean)

If you would like to set things up so that a particular menu modification appears only when a specific workbook is active, store your menu manipulation procedures in the Workbook_Activate and Workbook_Deactivate procedures. Refer to Chapter 19 for an example that uses toolbars.

0 0

Post a comment