Microsoft Office Tutorials and References
In Depth Information
4.7.2 Running Macros
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
End Sub
This is the same code that we might have written in order to perform this find and replace
operation.
In certain situations, the macro recorder can serve as a very useful learning tool. If we can't figure
out how to code a certain action, we can record it in a macro and cut and paste the resulting code
into our own program. (In fact, you might want to try recording the creation of a pivot table.)
However, before you get too excited about this cut-and-paste approach to programming, we
should point out that it is not anywhere near the panacea one might hope. One problem is that the
macro recorder has a tendency to use ad hoc code rather than code that will work in a variety of
situations. For instance, recorded macro code will often refer to the current selection, which may
work at the time the macro was recorded but is not of much use in a general setting, because the
programmer cannot be sure what the current selection will be when the user invokes the code.
Another problem is that the macro recorder is only capable of recording very simple procedures.
Most useful Excel programs are far too complicated to be recorded automatically by the macro
recorder.
Finally, since the macro recorder does such a thorough job of translating our actions into code, it
tends to produce very bloated code, which often runs very slowly.
4.7.2 Running Macros
As you may know, to run a macro from the user interface, we just choose Macros from the Macro
submenu of the Tools menu (or hit Alt-F8). This displays the Macro dialog box shown in Figure
4-12 . This dialog box lists all macros in the current workbook or in all workbooks. From here, we
can do several things, including running, editing, creating, or deleting macros. (Choosing Edit or
Create places us in the VB Editor.)
Figure 4-12. Excel's Macro dialog box
 
Search JabSto ::




Custom Search