Using the VBA Editor


After recording a macro, PowerPoint tries to reduce the sequence of recorded PowerPoint commands to a series of VBA commands that would have the same effect. If you find that you want to record more powerful macros, you may need to use the VB Editor. The VB Editor is a separate program you can use to customize, create, and debug macros using the VB programming language.

Editing a Macro Using the VB Editor

You may find that sometimes a macro is not working the way you had intended. This may be caused by the way your mouse and keystrokes were converted into Visual Basic. For example, if you record a macro and press the Page Down key five times (from slide one), it will be rewritten in Visual Basic as a macro that goes to slide six. To create a macro that would move down five slides, you would have to use the Visual Basic Editor to edit the default macro and make it work the way you intended.

To use the VB Editor and edit a specific macro:

  1. Choose Tools, Macro, Macros from the menu.

  2. Select the name of the macro to edit.

  3. Click Edit. The Visual Basic Editor is then launched, as shown in Figure 31.6, with the edit cursor positioned at the macro you chose. You can now edit the macro commands to modify how it works.

    Figure 31.6. The Visual Basic Editor enables you to manually edit a macro.

    graphics/31fig06.jpg

  4. Edit the macro as desired.

  5. Select File, Close and Return to Microsoft PowerPoint from the menu.

graphics/lightbulb_icon.gif

The Visual Basic Editor has a different Help file than PowerPoint does. To view VBE's Help file, choose Help, Contents and Index from the Visual Basic menu.


Using the VB Editor to Create a Macro

By including the Visual Basic Editor (VBE), PowerPoint gives you a built-in programming environment with a wealth of features. The editor is a subset of the popular Visual Basic language. Use the editor to edit, write, debug, and manage macro script code. The editor also has many useful windows that help you explore the VBA language.

You can open the editor in one of two ways:

  • Choose Tools, Macro, Visual Basic Editor from the main menu.

  • Press Alt+F11 while you're in any view.

There are entire books that focus on Visual Basic's impressive capabilities, but the following sections just highlight the basic features you need to create macros.

You can easily cut and paste or drag and drop sample code into a macro module. Open the Visual Basic Editor and choose View, Code from the menu, or press F7 to display the Visual Basic Editor window. After you copy or add VBA code to the window, the macros are automatically displayed and available in PowerPoint's Macro dialog box.

The Visual Basic Help files and Object Browser are useful reference sources; they can give you insight into the objects with which macro subroutines can work.



Sams Teach Yourself Office Productivity All in One
Sams Teach Yourself Office Productivity All in One (Sams Teach Yourself All in One)
ISBN: 0672325349
EAN: 2147483647
Year: 2003
Pages: 474
Authors: Greg Perry

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