Creating a Macro


When you record a macro, it's as though you've turned on a video camera that watches your keystrokes, mouse movements, and command selectionsthe macro recorder notes every move you make and converts your actions to programming code. After you name your macro and perform all the steps you want to automate, stop the recorder, and by using the name you've given the macro, you can run it at any time. A macro enables you to perform a virtually unlimited series of steps in just seconds.

NOTE

In earlier versions of Office, the Word, Excel, and PowerPoint programs didn't have features such as AutoCorrect and AutoText. Before these features existed, users created macros to correct common misspellings and turn abbreviations into words, phrases, and paragraphs. As Office evolves, the number of common tasks you'll need to automate by yourself will continue to decrease.


Recording a Macro

Before you begin to record a macro, you need to do some planning. Think about where you are in the process of developing or running a presentation when the macro you're about to create is invoked. What situation must exist for the macro to be successful? If the macro formats existing slide content, the content must be displayed and selected before the macro is run. If the macro runs a slideshow, the presentation must be placed in the same folder where the macro was recorded. In short, set the stage for your macro to begin, and record it only when the scenario is appropriate.

After you set the stage, record your macro by following these steps:

  1. Choose Tools, Macro, Record New Macro.

  2. In the Record Macro dialog box (see Figure 20.1), enter a macro name to replace the default name. Your macro's name cannot contain any spaces. If your macro name is more than one word, use an underscore to separate the words.

    Figure 20.1. Give your macro a short yet descriptive name.

    graphics/20fig01.jpg

  3. As needed, type a description of the macro in the Description box. It's a good idea to leave the name and date text that is already in the box and add your description at the end of that text.

  4. Click OK.

  5. Perform the steps you want to record, using the mouse or keyboard to issue commands.

  6. When your steps are complete and you reach the end of the procedure you want to automate, choose Tools, Macro, Stop Recording.

CAUTION

Try to test your macros immediately, especially if you've developed them for others to use. This will prevent any unpleasant surprises when you or another user attempts to use the macro, and enables you to edit it as needed while the procedures are fresh in your mind. The process of running a macro is discussed later in this chapter.


graphics/troubleshoot_icon.jpg

Can't get your macro to run the way you want ? See the " Troubleshooting " section near the end of this chapter.


Creating a Macro in the Visual Basic Editor

If you're familiar with VBA, you can build a macro without recording your steps as described in the previous section of this chapter. Instead, you can type the macro programming code directly in to an editing window provided by Office XP's Visual Basic Editor (see Figure 20.2).

Figure 20.2. Even a novice VBA user can learn a lot from building and editing macro code in this window.

graphics/20fig02.jpg

To enter the editor, select Tools, Macro, Visual Basic Editor, and then choose the macro you want to edit from the Declarations drop-down list (on the upper-right corner of the large module window). The editor consists of three separate windows each designed to assist you in the creation and editing of a macro:

  • Project The Project window shows a hierarchical tree, displaying your macro's modules or sections of code. A simple macro will probably have only one module.

  • Properties This window also lists the project's modules, but this time either alphabetically or by category.

  • Module The macro code appears in this window. Type new or edit existing VBA code in this window.

Figure 20.3 shows the Module window with the parts of a simple formatting macro identified.

Figure 20.3. A knowledge of VBA is required for building a macro from scratch in the Visual Basic Editor.

graphics/20fig03.jpg

To create a macro in the Visual Basic Editor, follow these steps:

  1. Choose Tools, Macro, Visual Basic Editor.

  2. Click inside the Module window to make it active.

  3. As needed, choose Insert, Module. This creates a blank module for you to begin writing your code.

  4. Type Sub followed by the name of your macro and press Enter. Your End Sub statement is added automatically (see Figure 20.4).

    Figure 20.4. If the name of your macro includes spaces, use the underscore character to represent them, as in Format_title.

    graphics/20fig04.jpg

  5. Type your lines of code for the steps your macro should perform.

  6. Choose File, Close and Return to Microsoft PowerPoint.



Special Edition Using Microsoft Office PowerPoint 2003
Special Edition Using Microsoft Office PowerPoint 2003
ISBN: 0789729571
EAN: 2147483647
Year: 2003
Pages: 261

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net