Hardware Reference
In-Depth Information
What can you do with an Office macro? The sky's the limit, but here are a few simple
examples, any of which could be done with a single click or keystroke:
• Perform a frequently used find-and-replace operation
• Format spreadsheet cells according to their contents
• Number all the instances of a certain phrase in a document
• Reformat a table
• Remove all the hyperlinks in a workbook
• Change all the tab stops in the current paragraph style
• Merge cells from two columns into a third column
• Resize all the graphics in a document
If you use Office extensively—and especially if you share documents with Windows users—it
might be worth the effort to learn a bit of VBA since (unlike AppleScript) its macros work
on both Windows PCs and Macs. But let me be frank: it's not great for beginners. VBA was
designed for programmers, not for ordinary users. It won't do you any good beyond Office
apps, and unlike AppleScript, VBA would never be called “English-like.” If you don't know
much about programming already, there's a significant learning curve.
However, there's a sneaky way to get your foot in the door—to write a VBA macro without
knowing any VBA at all. Office lets you record macros—that is, turn on recording, do some
stuff while Office watches, and then turn off recording. Office then attempts to make a VBA
macro out of whatever you just did, which you can then replay at will. Sometimes these
macros work fine as is; sometimes they require fiddling; and sometimes you're out of luck.
So, my advice if you want to automate an Office app is to try recording a macro first. If that
doesn't work (and you can't easily see how to fix it), move on to Automator. If Automator
won't do what you need either, try either AppleScript (if you need more control) or Keyboard
Maestro (if you want a simpler interface). Write your own VBA macro from scratch only if no
other tool does the trick.
Record Macros in Microsoft Office Apps
Let's walk through the process of recording and then playing back a simple macro. (I'll use
Word for this example, but the process is virtually identical in Excel and PowerPoint.)
1. Open a new, blank document in Word. (It doesn't have to be blank, but it's
easier that way for this example.)
Search WWH ::




Custom Search