Word 2008 Tip: Creating a direct command for pasting unformatted text

Posted by Pierre Igot in: Microsoft
January 28th, 2008 • 5:24 pm

If this blog post’s title sounds very similar to a previous Betalogue post title, it’s because it is. Back in 2004, I wrote a tip about creating a direct command for pasting unformatted text in Word 2004.

Thanks to the infinite generosity of Microsoft’s MacBU developers, we have to start all over again in Word 2008, because of the elimination of the Visual Basic for Applications macro scripting feature.

I am, in fact, very ambivalent about putting any further effort into customizing Word 2008. I am not a masochist. Who’s to say that Microsoft won’t break AppleScript support in the next version of Word for Mac OS X? What guarantee do we have that it’s worth reinvesting more time and effort into fixing Microsoft’s Mac software? Certainly, the history of my relationship with Microsoft software suggests that I should do as little as possible to make life tolerable—and use Apple’s Pages whenever I can.

Which is exactly what I plan to do. So I will only post tips for customizations that I find absolutely essential. One of those is direct access to a “Paste without Formatting” command. Apple’s Pages provides direct access to such a command, which is called “Paste and Match Style.” It’s in the “Edit” menu and it uses the command-option-shift-V shortcut, which is what I am used to.

If you want to paste unformatted text in Word 2008, on the other hand, you are forced to go through a multiple-step process. You can either used the “Paste Special…” command in the “Edit” menu and then choose the “Unformatted Text” option or use the regular “Paste” command (which pastes with formatting) and then click on that stupid toolbar button that appears floating in mid-air next to the pasted text and choose the option to “Match the Destination Formatting.”

Neither approach is acceptable for a task that I tend to repeat many, many times throughout the day.

So the other day I decided to try and figure out if there was a way to achieve this via AppleScript. I explored the flavour of AppleScript that Microsoft uses in Word, and found it very unpalatable—but it’s not like we have much choice, do we?

By the way, if you follow the link above, you’ll find that most of the documentation refers to AppleScript support in Office 2004. As far as I can tell, nothing much has changed between Office 2004 and Office 2008 in terms of AppleScript support. Microsoft did not even bother to provide us with recordable applications, which means that we are all forced to become developers and learn how to write scripts manually. Thanks, Microsoft.

Anyway, after much trial and error, here’s the script that I ended up using for this particular command:

tell application "/Applications/Microsoft Office 2008/Microsoft Word.app"
paste and format (text object of selection) type format plain text
end tell

I put a direct reference to the Word 2008 application rather than the more generic “Microsoft Word,” because I have kept a copy of Word 2004 on my system. Apparently, Microsoft recommends against running Word 2004 and Word 2008 in the same user environment and instead suggests to only run Word 2004 in a separate user environment and to switch back and forth with fast user switching. Fat chance of that happening on my machine. I’d rather live dangerously than waste my time trying to conform to Microsoft’s definition of a productive workflow. So I have Word 2004 and Word 2008 side by side and I’ll switch between the two if I want to, because, you know, Word 2008 is crap. Word 2004 is also crap, but a different kind of crap. Unfortunately, thanks to Microsoft’s infinitely helpful engineers, we now need both kinds of crap.

So does this little script actually work? Yes, if you don’t mind the totally illegible syntax. For a while I couldn’t get it to paste without replacing the entire contents of my document, but I then discovered that I was “telling” the wrong object. So now apparently this script tells the correct object and all is well—except that, after pasting, the insertion point is at the beginning of the newly pasted text rather than at the end. There is probably a complicated way to compute the length of the pasted text and move the insertion point manually to the other end, but I value my time. I’ll live with the insertion point at the beginning if I have to.

Now, how do you access this script in Word 2008? According to Microsoft’s own “Known issues in Office 2008,” it should be tricky:

Running Automator workflows and AppleScripts from the Office script menu is not currently supported under Mac OS X v10.5 (Leopard).

But I’ve found that, if I put the script in the “Word Script Menu Items” folder inside the “Microsoft User Data” folder, it does actually show up in the script menu in Word, and the command works. So who knows what they mean with this “known issue”? They can’t even get it right when things actually work as expected.

Better still, I was actually able to assign a shortcut to this command using Mac OS X’s built-in keyboard shortcuts feature in System Preferences. While the script menu is part of the Word 2008 menu bar, Word 2008 itself doesn’t actually let you assign keyboard shortcuts to the scripts in that menu. The “Customize Keyboard…” command does not mention scripts at all. So much for enhanced AppleScript support in Office 2008.

But since the script menu is, for most intents and purposes, a regular Word 2008 menu, apparently Mac OS X’s built-in keyboard shortcuts feature can be used to customize it. Phew.

I used the same command-option-shift-V shortcut as in Pages, even though Word 2008 already uses it by default for the “Paste Special…” command. Apparently, the script menu shortcuts supersede the built-in shortcuts. Yey. (I still removed the shortcut from the “Paste Special…” command, just in case.)

So there we are. I have a more or less functional “Paste without Formatting” command in Word, and I can use the same shortcut as in Pages. I guess I’ll just have to get used to the insertion point being at the beginning of the text after pasting. If anyone ever finds an easy way to move it to the end, please share!

12 Responses to “Word 2008 Tip: Creating a direct command for pasting unformatted text”

  1. somethingorother5 says:

    Thank you so much for posting this. I’m constantly pasting content from the web, so having to change the formatting around was always a serious pain. I can’t believe they didn’t change this behavior in Word 2008 as it was a big annoyance in Word 2004.

    I can’t believe they don’t at least have a preference to always paste using the destination formatting. I can’t really think of many times where I have wanted to keep the source formatting.

  2. Pierre Igot says:

    I am afraid Microsoft is not in the business of fixing their software’s numerous annoyances. They are in the business of trying to make as much money as possible with as few improvements as possible.

  3. MagnusB says:

    tell application “/Applications/Microsoft Office 2008/Microsoft Word.app”
    paste and format (text object of selection) type format plain text
    end tell
    tell application “System Events”
    tell application “/Applications/Microsoft Office 2008/Microsoft Word.app” to activate
    key code 124 using command down
    end tell

  4. Pierre Igot says:

    Magnus: I am afraid your script doesn’t seem to make any difference. Sometimes it moves the cursor to the right by a word, but that’s about it. Don’t know what character code 124 is supposed to be, but the keyboard shortcut in question doesn’t miraculously jump from the beginning to the end of the just-pasted text, at least on my system (with Canadian CSA keyboard layout).

    Maybe you could clarify how your script is supposed to work?

  5. Joe Kissell says:

    Try this one…

    tell application "/Applications/Microsoft Office 2008/Microsoft Word.app"
    tell selection
    set theClip to Unicode text of (the clipboard as record)
    type text text theClip
    end try
    end tell
    end tell

  6. Pierre Igot says:

    Yes, this works much better. Obviously a completely different approach, but what matters is that it works as expected. Thanks a bunch!

  7. daigoro says:

    I’ve tried both of these. The script menu highlights, but no text gets pasted. (To double-check I then do a standard paste which results in the text being pasted). I’m completely current on both Word and Leopard.

  8. Pierre Igot says:

    You might have to quit/relaunch Word. As per usual, scripting support is pretty flaky, at least in my experience.

  9. Keyboard shortcut to paste unformatted text into Word 2008 for the Mac | Jim's Junk Drawer says:

    […] Then use System Preferences to set a keyboard command for the resulting script menu item. A kludge, but seems to work. I found this here. […]

  10. Tipp: Tastaturkürzel für Einfügen von unformatiertem Text in Word 2008 says:

    […] bei Pierre Igot. Autor: Datum: Kategorie: Tags: Hendrik Auf’mkolk , Redakteur 09.03.2009 […]

  11. Coller sans mise en forme says:

    […] pouvez sans doute directement lire et utiliser les sources que j’ai moi-même utilisées: ici et […]

  12. Betalogue » Really Smart Paste: Keyboard Maestro and BBEdit to fix copied text from on-line database and other sources says:

    […] the years, I have struggled with the idiosyncrasies of the target applications that I use (mostly Pages ’09 and Word 2011, […]

Leave a Reply

Comments are closed.