Section 14.2. Running Macros


14.2. Running Macros

Running macros in PowerPoint is, fortunately, easier than writing them. Running macros is also an important part of testing them to make sure they work. Because files containing macros can also have computer viruses, PowerPoint wants to make sure you know what you're doing before running a file containing macros (that is, a file saved with the .pptm extension). First, you must set PowerPoint's security options to tell PowerPoint it's okay to run macros. Then you can open the file and tell PowerPoint to run the macro. The following sections walk you through the process.

14.2.1. Setting Security Options

Because macros and add-ins can wreak havoc on your computer, PowerPoint lets you choose how (or even whether) to open them. Because add-ins contain macros, the security options you set in this section also affects whether and how PowerPoint lets you open add-in files (files bearing the .ppam extension).

FREQUENTLY ASKED QUESTION
Macro, Add-in, or ActiveX Control?

What's the difference between a macro, an add-in, and an ActiveX control? Why would I use one over the other? Do they pose similar security risks?

Macros, add-ins, and ActiveX controls have a lot in common. You can automate, extend, and enhance your PowerPoint presentation with all three, and all three present serious security risks (page 425).

Here's the skinny on each:

  • Macros. A macro is a named set of VBA statements that act on your PowerPoint presentation while it's being edited or while it's running. Only PowerPoint files with the extensions .pptm, .potm, .ppsm, and .ppam can contain macros.

    Add-ins. An add-in is nothing more than a compiled collection of macros. PowerPoint (technically, Office) defines a special set of rules for add-ins, letting add-in programmers add their own custom buttons to PowerPoint tabsin effect, letting them extend PowerPoint. These rules give folks who use add-ins a formal way of installing and managing them (Chapter 13). Because add-ins contain macros, they pose the same security risks as macros (although PowerPoint does let add-in creators digitally sign their add-ins for a measure of added accountability). PowerPoint 2007 add-ins carry the .ppam file extension.

  • ActiveX controls. An ActiveX control is a small, reusable chunk of code (typically written in C++, Java, or Visual Basic) that gives PowerPoint developers a quick way to add objects such as scroll bars and ad banners to their PowerPoint slides and then customize those objects (like specifying their own list of drop-down options). You'll find the ActiveX controls that come with PowerPoint on the Developer tab; others are available for download on the Web. Because ActiveX controls (files with .ocx or .dll extensions) can access the vital organs of the Windows operating system itself, they can be more dangerous than both macros and add-ins. You never, ever, want to run an ActiveX control from a source you don't trust (page 425).


To set macro security options:

  1. On the Developer tab, click Macro Security to adjust your security settings.

    The Trust Center (Figure 14-6) appears. (To display the Trust Center you can click Office button PowerPoint Options Trust Center Trust Center Settings.)

    Figure 14-6. When you're running macros and add-ins, security's no joke. Only you can decide how safe is safe, but most people find the "Disable all macros with notification" and "Disable all macros except digitally signed macros" options balance reasonable security with a reasonably acceptable risk.


  2. Adjust PowerPoint's macro security level by turning on the radio button next to one of the following:

    • Disable all macros without notification. Tells PowerPoint not to let you know when it loads a file containing a macro, but instead to quietly ignore it.

    • Disable all macros with notification. Directs PowerPoint to pop up a message telling you when it detects a macro-containing file (but not to run the macro). Choosing this option lets you decide if you want to run the macro and, if so, to stop, adjust PowerPoint's security settings, and relaunch the macro-containing file.

    • Disable all macros except digitally signed macros. Tells PowerPoint to run only those macros whose creators digitally signed them. (See the box on page 425.)

    • Enable all macros (not recommended, potentially dangerous code). Directs PowerPoint to run any macro it encounters. Choosing this option is the computer equivalent of leaving your front door, your back door, and all your windows wide openand then taking off for a year-long vacation in Bermuda.

  3. Tell PowerPoint if you want to run macros containing instructions for manipulating the PowerPoint object model.

    Some macros have the ability to choose which slide (or slideshow) to display. If you want to let macros manipulate your slides and slideshows, turn on the checkbox next to "Trust access to the VBA project object model." (For more on the ramifications of this decision, see the box on page 425).

  4. When you're done, click OK.

    The Trust Center disappears, and PowerPoint pops you back to the Developer tab.

14.2.2. Testing a Macro

Not even professional programmers expect to write a macro in one shot and have it work perfectly . Editing and testing, and reediting and retesting are what writing macros is all about.

To test a macro:

  1. On the Developer tab, click Macros.

    The Macro dialog box appears.

    UP TO SPEED
    Battening Down the Hatches

    Macros can do all sorts of nasty things to your computer. Working in concert with other malicious files, they can surprise you in the middle of a slideshow by displaying content you've never seen (and wouldn't want your mother to see), erase files, and more.

    Security is always a tradeoff . The more access you grant the macros you let PowerPoint run on your computer, the greater the risk that one of them will cause you grief .

    Yes, you can unhook your computer's Internet connection and tell PowerPoint to never, ever run a macro but in PowerPoint, as in life, a common-sense, approach that lets you benefit from the good while limiting the bad makes more sense.

    Here's a short list of what you can do to get the power of macros while still protecting yourself as much as possible:

    • Buy antivirus software and use it.

    • Password-protect your computer and don't give anyone your password.

    • Back up religiously .

    • Never turn macro security off. Choosing to enable all macros (page 424) gives hackers carte blanche to your computerand, if you're running on a network, to your coworkers' computers, as well.

    • Never let a macro, add-in, ActiveX control, or any other program from an untrusted source run on your computer. In Microsoft terms, an untrusted source is a macro creator you haven't personally added to your trusted source list based on the creator's digital certificate. In real-world terms, an untrusted source is any individual or company you've never heard of and wouldn't willingly give your credit card number to. Page 424 shows you how to bar programs from untrusted sources.



    Note: Clicking Step Into (Figure 14-7) lets you run your macro in the VBA debugger, which is good for heavy-duty, line-by-line testing.
  2. In the Macro dialog box, click to select the name of the macro you want to run and then click Run, as shown in Figure 14-7.

    Figure 14-7. The Macro dialog box you see in PowerPoint 2007, shown here, is identical to the one that PowerPoint 2003 offered . Notice the extension on the PowerPoint file; the .pptm stands for macro-enabled PowerPoint presentation. (You can't save a macro to a standard .pptx file.)


    The macro runs (see Figure 14-8).

    Figure 14-8. Behold! The result of running the VBA MsgBox statement on page 420.



Tip: In addition to the Macro dialog box shown here, PowerPoint also lets you run a macro from a customized icon you place on the Quick Access toolbar. For details, check out page 394.

14.2.3. Adding a Macro to a Slideshow

Unlike images, charts , text, and other objects you add to your slides, macros don't automatically appear on your slidesand they don't automatically run when you run your slideshow, either. So after you create a macro, you need to tell PowerPoint when and how to run it. One of the easiest ways is by adding an action button to a slide and then hooking it up to your macro.

Here's how:

  1. Add a custom action button to your slide. (See page 384 for instructions.)

    The Action Settings dialog box appears.

  2. In the Action Settings dialog box, choose "Run macro" and then, from the drop-down box, choose the macro you want to run when this button is clicked. When you finish, click OK.

    The Action Settings dialog box disappears.

  3. Test your macro in slideshow mode.

    To do so, run your slideshow and click the action button.

UP TO SPEED
Finding Macros to Run

With the macro recorder out of the picture, creating macros is no longer in the reach of mere mortals . The fact is, you have to be a crackerjack VBA programmer to create a useful macro in PowerPoint 2007.

Downloading macros from the Internet isn't really an option, either. For one thing, macros are a breeding ground for viruses. For another, macros are typically so short and so situation-specific that it doesn't make sense for programmers to post them on the Web. Like poems published a line at a time, free macros don't do exactly what you want, and you have to do so much cobbling together you might as well have written them yourself.

If you don't want to spend a lot of time learning VBA, you can hunt for a PowerPoint add-in that does what you want. You can find add-ins all over the Web (page 415), and they're designed to help in a wide variety of PowerPoint situations.



Note: PowerPoint's security restrictions don't let you create a macro that runs automatically, as soon as the slideshow runs. If that's what you want to do, you need to create a PowerPoint add-in. (See the box on page 423.)



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