Section 14.1. Creating and Editing Macros


14.1. Creating and Editing Macros

Starting with PowerPoint 2007, Microsoft ditched the macro recorder that let you create macros simply by stepping through the tasks you wanted to automate (see the box above). That means the only way to create and edit macros in PowerPoint 2007 is by using the Microsoft Visual Basic Editor, which you'll learn about in the following steps.

14.1.1. Creating a Macro

The tools you need to create macros are on PowerPoint's Developer tab, which doesn't show up automatically when you first install the program. So the first step in creating macros is to bring the tab out of hiding. Unlike documents, which you don't have to name until you save them, with macros you have to make some decisions upfront in the Macro dialog box.

  1. Select Office button PowerPoint Options Popular, and then turn on the checkbox next to "Show Developer tab in the Ribbon." Click OK.

    The Developer tab appears (see Figure 14-1).

    Figure 14-1. Before you can work with macros, you have to display the Developer tab shown here.


  2. Choose Developer Code Macros.

    The Macro dialog box (Figure 14-2) appears.

  3. In the "Macro name" box, type the name of your new macro (see Figure 14-2).

    Keep the name simple and descriptive and make sure it doesn't contain spaces or punctuation marks.

    PowerPoint activates the Description box and the Create button.

    Figure 14-2. Until you've created at least one macro, most of the options displayed on the right side of the Macro dialog box are grayed out.


  4. From the "Macro in" drop-down box, click the name of the presentation you want to add the macro to.

    In most cases, you should pick the name of your current presentation, which PowerPoint helpfully supplies . You can also choose to add the macro to "All open presentations."

  5. In the Description box, type a line or two describing the purpose and behavior of the macro. When you finish, click Create.

    The Microsoft Visual Basic for Applications editor appears (Figure 14-3).

    Figure 14-3. When you start working in the VBA editor, you'll see the name and description you typed in the Macro dialog box to start you off. To create a macro, you type Visual Basic commands rather than clicking buttons or choosing from menus . You can choose Help to display the VBA language reference, but the instructions assume a familiarity with VBA.


  6. In the code module window, type the VBA code for your macro. Try typing the following:

     MsgBox("Hello! It's good to see you again.") 

    As you start typing, the VBA editor helps out by displaying a description of correct VBA syntax (Figure 14-4).

    Figure 14-4. The VBA editor doesn't leave budding programmers out in the cold. The instant it recognizes the beginning of a legitimate VBA statement, it displays the correct syntax for that statement. Use that structure to make sure you're typing the command correctly.


  7. When you finish typing your VBA code, choose File Save [Presentation Name].

    The Save As dialog box appears.

  8. In the Save as Type box, choose "PowerPoint Macro-Enabled Presentation (*.pptm)" and click Save.

    If you forget and accept the standard file format, the message you see in Figure 14-5 pops up.

    Figure 14-5. You can't save a macro to a regular PowerPoint presentation file (.pptx). If you try, PowerPoint kicks up this error message. The only file formats PowerPoint lets you save macros to are .pptm, (macro-enabled PowerPoint presentation), .potm (macro-enabled PowerPoint template), .ppsm (macro-enabled PowerPoint show), and .ppam (macro-enabled PowerPoint add-in).


  9. In the VBA editor, choose File "Close and Return to Microsoft PowerPoint."

    The VBA editor disappears, and you see the PowerPoint interface once again.


Note: Instead of creating a macro-enabled presentation, you can create (or save your macro to) a macro-enabled template (.potm), a macro-enabled PowerPoint stand-alone show (.ppsm), or a PowerPoint add-in (.ppam). If you create a macro-enabled template file, though, beware: Creating a new presentation from a macro-enabled template file does not automatically attach your macro to the presentations folks create based on that template.

14.1.2. Opening a Macro for Editing

Once you've written a macro, you can always go back and change it or add to it. In fact, most macros change and grow significantly over the course of their lifetimes.

UP TO SPEED
VBA Help for Macro (and Add-in) Creators

If you want to learn more about creating your own macros and add-ins, you'll soon graduate beyond this book. Some places to start:

  • ISV Zone: Visual Basic for Application . On this MSDN site you find an FAQ, a downloadable VBA reference, technical articles and forums, and much more (http://msdn.microsoft.com/isv/technology/vba).

  • Microsoft's Ribbon Developer Center (http://msdn.microsoft.com/office/tool/ribbon/default) tells you all you need to know about extending PowerPoint ribbons with add-ins and macros, including a style guide, code samples, and multimedia how-to presentations. You can find more useful articles on extending PowerPoint at http://msdn2.microsoft.com/en-us/library/ms406046.aspx.

  • Microsoft Visual Studio (http://msdn.microsoft.com/vstudio) includes a wizard that walks you through the process of creating PowerPoint add-ins.


  1. On the Developer tab, click Macros.

    The Macro dialog box appears.

  2. In the Macro dialog box, click to select the name of the macro you want to edit and then click Edit.

    The VBA editor launches, and in the code module window, you see the code for your selected macro.




PowerPoint 2007
PowerPoint 2007
ISBN: 1555583148
EAN: N/A
Year: 2006
Pages: 129

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