Page 302 - Excel Workbook for Dummies
P. 302
32_798452 ch22.qxp 3/13/06 7:48 PM Page 285
Chapter 22
Using Macros
In This Chapter
Understanding how macros work
Recording macros in a worksheet
Using the relative option when recording macros
Assigning macros to custom toolbars and pull-down menus
acros enable you to automate almost any task that you can undertake in Excel. By
Musing Excel’s macro recorder to record tasks that you perform routinely, you not only
speed up the procedure considerably (as Excel can play back your keystrokes and mouse
actions much faster than you perform them manually), but you are also assured that each
step in the task is carried out the same way each and every time you perform the task.
In this chapter, you get a chance to practice recording, testing, and playing back macros
that you use to automate repetitive tasks required when building and using your Excel
worksheets and charts. You also have the opportunity to practice assigning the macros
you record to custom menu items and toolbar buttons.
Creating Macros
You can create macros for your Excel spreadsheets in one of two ways:
Use Excel’s macro recorder to record your actions as you undertake them in a
worksheet
Enter the instructions that you want followed in VBA code in the Visual Basic Editor
Either way, Excel creates a special module sheet that holds the actions and instructions in
your macro. The macro instructions in a macro module (whether recorded by Excel or writ-
ten by you) are stored in the Visual Basic for Applications programming language. You can
then study the VBA code that the macro recorder creates and edit this code in the Visual
Basic Editor, which you open by choosing Data➪Macro➪Visual Basic Editor or by pressing
Alt+F11 (see Chapter 23).
Using the macro recorder
You can use the macro recorder to create many of the utility-type macros that perform the
repetitive tasks necessary for creating and editing your worksheets and charts. When you
turn on the macro recorder, the macro recorder records all of your actions in the active
worksheet or chart sheet as you make them.