Microsoft Office Tutorials and References
In Depth Information
Macros and Modules
MAcros And ModulEs
In Lesson 2, you used the Macro Recorder to create a macro named mySort . You learned how to
assign a shortcut key to the macro, and how to enter a brief description of what the macro does.
You also learned about a couple of ways to run the macro by using either the shortcut key or the
Macro dialog box. One thing you have not been shown yet is the macro itself, or even how to find it.
locating your Macros
When the Macro Recorder created the mySort macro in Lesson 2, it also created a module in which
to store the macro. If this module happens to be the first module of the workbook, as was the case
for mySort , the Macro Recorder will name the new module Module1 by default. If the Macro
Recorder creates another module after that, it assigns the default name of Module2, and so on.
In the Project Explorer window, expand the bolded VBAProject title (my Project workbook name is
MacroExamples.xlsm) and expand the yellow Modules folder to show the module named Module1.
To see the VBA code in that module, you can double-click the module name, or you can right-click
the module name and choose View Code as shown in Figure 4-2.
The mySort macro will appear in the Code window for Module1. Based on the steps you took while
recording the mySort macro in Chapter 2, Figure 4-3 shows the exact code that was produced by
Macro Recorder in Excel version 2003.