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

Posted by Pierre Igot in: Macintosh
June 9th, 2004 • 4:56 am

When you copy text from a web page in Safari, what gets copied to the Clipboard is formatted text, i.e. text with typical font formatting such as font face, colour, size, style, etc.

If you then go to Word 2004 and try to paste that text into your Word document, it will paste it as formatted text, with all the formatting, which is usually not appropriate when you want to reuse the text in a Word document, where you typically want to use the formatting of your document’s text instead.

There is a way to avoid this, but it’s rather painful. After you’ve copied text in Safari, you go to Word, you go to the “Edit” menu, you select the “Paste Special…” command and then you choose the “Unformatted Text” option and press OK. Not exactly convenient.

Today, I wanted to add a direct command for this to my “Edit” menu. First, I went to Word’s “Customize” dialog to see if, by any chance, Word included such a direct command in its extensive list of commands, of which only a subset is part of the default Word user interface. Even taking into account the very inconsistent and confusing way Microsoft named these commands, I was unable to find such a command.

So I decided to create a short macro instead. I cannot be bothered with learning the whole VisualBasic macro language, so usually when I want to create a new macro I put Word in macro recording mode and do the various actions that I want it to record as a macro, and then I stop the recording and go to the macro editor to fine-tune the macro.

So in this case, I copied some formatted text from Safari, then started recording a macro in Word, went to the “Edit” menu, selected “Paste Special…“, selected the “Unformatted Text” setting, pasted the text, and stopped the macro recording process.

I immediately tried the macro as recorded again, and found that the new macro caused Word to paste formatted text (i.e. the default behaviour for the regular “Paste” command) rather than unformatted text. So I fired up the macro editor and looked at the macro as recorded by Word:

Sub EditPasteUnformatted()
    Selection.PasteAndFormat (wdPasteDefault)
End Sub

I searched for PasteAndFormat in the Visual Basic help and found the following (cropped):

VB Help for PasteAndFormat

First of all, wdPasteDefault is not listed as a possible value for Type on this help page. Secondly, it’s quite obvious that the value I wanted for this variable is wdFormatPlainText.

Why didn’t Word record my actions properly and use that value rather than wdPasteDefault? I have no idea. You’ll have to ask someone at MIcrosoft. But anyway, after changing the value, the macro finally worked as expected, and I was able to add it to my user interface in Word.

I hope this will be of some use to someone else.


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

  1. sdimbert says:

    Pierre,

    Can you please send me the entire Macro? “Paste Unformatted Text” is a key shortcut I desperately miss from Word for Windows (shift-ctrl-V).

  2. Pierre Igot says:

    The entire macro is:

    Sub EditPasteUnformatted()
        Selection.PasteAndFormat (wdFormatPlainText)
    End Sub
    

    Add it to your macros. Then you can assign the ctrl-shift-V shortcut to it with the Customize Keyboard dialog.

  3. Pierre Igot says:

    Mmm, I take that back. It doesn’t seem to work automatically for macros, only for built-in commands. Darn.

  4. Pierre Igot says:

    Normally, it should do it automatically. Might not work right if you have more than one shortcut assigned to the same command. (Doesn’t know which one to display.)

  5. Pierre Igot says:

    Yes, I also put it in my menu, just in case I ever forget the keyboard shorcut I’ve assigned to it :).

  6. sdimbert says:

    Can you get Word to diplay the keyboard shortcut in the menu?

  7. sdimbert says:

    Thanks a lot! This has bothered me for a long time.

    Your instuctions were great and I even got it into the Menu:

    http://unix.dimbert.net/menu.jpg

  8. Nancy says:

    I am still using Word X and my experience was a little different. I had to name the macro ?EditPasteUnformatted? (without the quotes) or be stuck with the name ?Macro1.?

    I recorded the macro and got this language:

    Sub EditPasteUnformatted()
    Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
    wdInLine, DisplayAsIcon:=False
    End Sub

    I got some help with the above macro naming convention at:
    http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=128
    where I also found out I could clean up the code a bit by shortening the instructions to:

    Selection.PasteSpecial Link:=False, DataType:=wdPasteText

    Thanks for starting me off in the right direction. This is a very useful shortcut.

  9. Pierre Igot says:

    Nancy: Thanks for the additional information!

  10. Li-Ou says:

    Wow thanks a lot. Really needed this tip. =)

  11. ClintMacD says:

    Pierre:

    Every time I set up a new Macintosh, this is the first tip I come back to.

    Thanks, again!

    Best wishes, Clint

  12. Pierre Igot says:

    Unfortunately, it no longer works with Word 2008. :-/

Leave a Reply

Comments are closed.