Writing Your Own Macros

Activating the Ribbon's Developer Tab 16

Displaying the Visual Basic Editor 16

Touring the Visual Basic Editor 17

Understanding VBA Procedures 19

Creating a Command Macro 19

Creating a User-Defined Function 23

Taking Advantage of IntelliSense 27

Shutting Down the Visual Basic Editor 30

Letting VBA do all the work by recording your macros is an easy way to automate tasks, and it's a technique you'll use often. However, to get the most out of VBA you need to do some full-fledged programming, which means writing your own macros, either from scratch or by using a recorded macro as a starting point.

Why go to all that trouble? Here are just a few of the advantages you gain by doing this:

■ If you make a mistake while recording a macro, particularly one that requires a large number of steps, you can make a simple edit to the macro's VBA code to fix the mistake rather than re-record the whole thing from scratch.

■ You get full control over each macro, which means you ensure that your macros do exactly what you need them to do.

■ You can take advantage of the hidden power of VBA to manipulate the Office programs and to perform some impressive programming feats that are simply not available via the recording process.

To help you realize these advantages and many more, this chapter introduces you to the basics of writing simple procedures and functions, as well as how to get around in the Visual Basic Editor, which is the tool that VBA provides for writing macros by hand. This sets the stage for the next few chapters, where I take a closer look at the specifics of the VBA language.

0 0

Post a comment