Page 59 - Microsoft Office Excel 2003 Programming Inside Out
P. 59

Exploring Visual Basic for Applications






















                               8  Select the macro you want to assign to the toolbar button and click OK.
                               9  In the Customize dialog box, click Close.
                                                                                                             Chapter 3
                             Assigning a Macro to a Menu Item
                             Just as you can create toolbars to hold toolbar buttons that run your macros, you can create
                             custom menus to serve the same purpose. While toolbars and menus are functionally equiv€
                             alent, there are two possible arguments in favor of adding a macro to a menu instead of a
                             toolbar. The first argument is that there is usually room to add a new menu to the main menu
                             bar. Also, because menus don’t display their full contents until you open them, menu items
                             don’t take up valuable real estate on a toolbar in the Excel window. The second argument in
                             favor of using menus over toolbars comes down to personal preference. If you like using the
                             menu system, assign your macros to menu items; if you prefer to use toolbar buttons, create
                             a new toolbar.
                             To assign a macro to a menu item, follow these steps:

                               1  Click Tools, Customize. If necessary, click the Commands tab.
                               2	 In the Categories list, click New Menu and drag the new menu to the right end of the
                                  main menu bar.
                               3	 Right-click the new menu, and click Name. Type your new menu name, and press
                                  Enter.
                               4  In the Categories pane of the Customize dialog box, click Macros.
                               5	 In the Command list, drag the Custom Menu Item command to the head of your new
                                  menu. When a box appears under the new menu head, drag Custom Menu Item onto it.
                               6  On the new menu, right-click Custom Menu Item and then click Name.
                               7  Type a new name for the menu, and press Enter.






                                                                                                        33
                                                                                        Part 2:  Visual Basic for Applications
   54   55   56   57   58   59   60   61   62   63   64