Page 307 - Excel Workbook for Dummies
P. 307
32_798452 ch22.qxp 3/13/06 7:48 PM Page 290
290 Part VII: Macros and Visual Basic for Applications
19. Type January in cell A4 and then click the Enter button on the Formula bar.
20. Drag the Fill handle to the right to extend the range to L4 so that all 12 months
from January through December are entered in the range A4:L4.
21. Click the Bold and Italic buttons on the Formatting toolbar and then choose the
Format➪Column➪AutoFit Selection menu command.
22. Click cell A4 to deselect the range A4:L4 and then click the Stop button on the
Stop Recording toolbar.
23. Test the Twelve_Months macro by positioning the cell cursor in cell C8 of Sheet1
and then pressing Ctrl+Shift+M.
Excel correctly enters the 12 months of the year in the cell range C8:N8 while at
the same time adjusting the widths of columns C to N to suit the length of the
month each contains.
24. Exit Excel and select No in the first alert dialog box prompting you to save your
changes to the Book1 workbook file, but select the Yes button in the second
alert dialog box when prompted to save your macros in the Personal Macro
Workbook.
Assigning Macros to Toolbars and Menus
Just as with hyperlinks (Chapter 21), Excel enables you to assign macros you create to
the custom buttons that you add to toolbars and to the custom menu items that you
add to the Excel pull-down menus. You can also assign macros to any graphic object
that you draw or import into Excel. When you assign a macro to a toolbar button, pull-
down menu item, or a graphic object, you can then run the macro simply by clicking
the button or graphic or by choosing the menu item from its pull-down menu.
Try It
Exercise 22-3: Assigning Macros to Custom Menus and Toolbars
Launch Excel and then use Sheet1 of the new Book1 workbook to practice assigning
the two macros that you created in Exercise 22-2 to add custom menu items and tool-
bar buttons:
1. Choose the View➪Toolbars➪Customize menu command to open the Customize
dialog box.
2. Click Insert on the menu bar to open this menu. Click the Commands tab and
then click Macros in Categories list box on the left.
3. Drag the Custom Menu Item from the Commands list box to the menu bar and
then drop it on the Insert menu to the very bottom of the Insert menu immedi-
ately below Hyperlink.
The Custom Menu Item now appears as the very bottom of the Insert pull-down
menu.
4. Right-click Custom Menu Item at the bottom of the Insert menu and then, on the
shortcut menu that appears, change the Name from &Custom Menu Item to
MOM Compan&y Name.