RSS
Follow us on:
  • Recommend:
  • 0 Comments

Office XP Tips: More Power From Macros

Here's a robust macro you can create without a degree from MIT.

Last week I described Office XP macros and how to record them.

As I boldly proclaimed, you can save yourself a ton of time and trouble by recording commonly used keystrokes in a macro and running it whenever you need those keystrokes. When you record your keystrokes in a macro, you are creating code in a programming language called Visual Basic for Applications (known in Star Trek circles as VBA), which Word, Excel, and PowerPoint understand.

You can record and run macros until the end of time without ever learning the underlying code. However, it can be helpful to know what it looks like so you can troubleshoot macros that don't do what you expected. Also, by spending a few minutes with the Visual Basic editor, you can learn how to insert useful code from friends, loved ones, and complete strangers.

One great way to take advantage of macros that others have created is by copying and pasting their code into your VBA editor and saving it as your very own macro. From time to time, I'll present code you can use in this manner. If you're squeamish about programming, don't fret. It's not necessary to understand the syntax of the code--you simply copy it and paste it into the VBA editor. It's kind of like when your English teacher told you what James Joyce was saying in Finnegans Wake: You don't have to understand it as long as you can spout it back when it's time to take the test.

Let's get the ball rolling this week with a handy macro that changes the way Word's Insert Picture dialog box works.

The Devil Is in the Details

A considerate reader named David Marchand, of Montreal, Canada, recently wrote to me about Word 2002's Insert Picture command. When you choose Insert, Picture, From File to find a picture to insert into your Word document, the Insert Picture dialog box presents a Thumbnail view of the image files in the current folder. Thumbnails are handy for locating an image, but David's a fan of the Details view. To switch to Details view, choose Insert, Picture, From File to open the Insert Picture dialog box. You'll find a row of icons along the top of the dialog box. The View icon is the rectangular box second from the right, next to Tools. Click the View icon's drop-down arrow and choose Details. In the Details view you can sort pictures according to size, type, or date. This can be handy for quickly locating a picture instead of scrolling through the Thumbnail view to find it.

That's all well and good, but once you set the view to Details, insert your picture, and then open the dialog box again to insert another one, the view reverts back to Thumbnail. David wanted a way to set the view to Details permanently. To the rescue comes Bob Buckland, manager of the Microsoft Office forum on CompuServe. Bob wrote a macro that sets the Insert Picture dialog box's default view to Details.

The Details Macro

Here's how to create the macro: First, open Word and choose Tools, Macro, Macros. When Word presents the Macros dialog box, type InsertPicture (with no space) in the Macro name text box. Choose "Normal.dot (global template)" from the "Macros in" drop-down list and click Create. Word will open the Visual Basic editor and place the cursor in a section called "Sub InsertPicture()." Move the cursor to the line immediately following "Inserts a picture from a graphics file." You're going to paste Bob's code there. Copy the code from our Web site.

You can either open the file from its current location or download it. Either way, copy the text and then paste it into the Visual Basic editor.

Now save and close the macro: In the Visual Basic editor, choose File, Save Normal. Then choose File, Close and Return to Microsoft Word.

Although this is a macro, you don't run it like you would normally. Instead, it replaces the Insert Picture command with a new command that's exactly like the old one, except the default view is Details. So whenever you choose the Insert, Picture, From File command, you're running the macro.

Thanks to David for alerting me to this macro and thanks to Bob for sharing it with us. You'll find other helpful macros at Bob's site.

(Click the "Word Macros & VBA" link on the left side of the page.)

Would you recommend this story? YES NO

  • Recommend:
  • 0 Comments
  • Become an Android authority

    Play music or games, run productivity apps and essential utilities.

  • Speed Up Everything!

    PCWorld shows you the secrets to improve performance on all your hardware.

Lenovo Laptop Deals

Subscribe to the BizFeed Newsletter - weekly

See All Newsletters »
Today's Special Offers