Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Pasting Clean Text.

Pasting Clean Text

by Allen Wyatt
(last updated March 8, 2017)

7

I paste a lot of text. (I mean a LOT of text.) When I am copying and pasting text within the same document, it is no problem. When I am copying text from other places, however, pasting that text into a Word document can have strange effects. This isn't a Word problem; it is something about the text I am copying and pasting that causes funky appearance of the text.

To get around this, I normally choose Edit | Paste Special and make sure that the text I am about to paste will be added to the document as unformatted text. Of course, since I paste so much text, continually choosing Edit | Paste Special can be bothersome.

The solution, for me, was to create a very short macro that does the pasting I want—as unformatted text. The following macro, PasteClean, does just that:

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

To make this macro an even more valuable editing tool, I assigned it to a custom tool on the toolbar. Now, when I want to paste a clean copy of what text is in the Clipboard, I simply click the tool and the macro does the rest.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1310) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Pasting Clean Text.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using Find and Replace to Pre-Pend Characters

Need to add some characters to the beginning of the contents in a range of cells? It's not as easy as you might hope, but ...

Discover More

Assigning a Macro to a Button in Your Text

One way you can access macros is through the use of a button, added directly into the text of your document. This is done ...

Discover More

Printing Documents in a Folder

If you want to print a group of documents at the same time there are a couple of ways you can accomplish the task. Here are ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Deleting a Range of Pages

Need to delete a range of pages out of the middle of your document? It's easy to do using editing techniques you already know ...

Discover More

Adding Hyphens to Phrases

Editing text to turn regular words into hyphenated phrases can be a real bother. The chore can become a breeze if you apply ...

Discover More

Capitals After Colons

Do you want Word to always capitalize the first letter appearing after a colon? The program won't do it by default, but there ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 0?

2016-03-09 17:23:36

Richard Ong

Thank you so much, Ned. That new command works like a charm. I recorded a new macro and it came up with:

Selection.PasteAndFormat (wdPasteDefault)

and that wasn't working.

I don't allow automatic updates and recently installed a big backlog of updates. My troubles may have begun then for the reason you suggest.

You've saved me from one of life's persistent niggling irritations!


2016-03-08 09:30:47

Ned Zimmerman

Richard,
like you I had a macro that used
Selection.PasteSpecial DataType:=wdPasteText

for years without issue.

The commenter in the thread you linked to missed the point. The issue isn't that the Clipboard is empty, it's that it contains something that isn't text.

I believe a recent MS security update for Word has changed the PasteSpecial behavior in Word 2007 so that it now throws the runtime error 5342 if the data type of the clipboard contents is not text.
Previously it would just attempt to grab whatever text was in the Clipboard contents and paste that only. My guess is that someone figured out a way to abuse this behavior.

If you record a new macro to paste text unformatted you will now see the following:

Selection.PasteAndFormat wdFormatPlainText

This does what you want without throwing the runtime error.

We all just need to update our macros.


2016-02-27 13:15:48

Richard Ong

PS:

A commenter at this site

http://answers.microsoft.com/en-us/office/forum/office_2007-customize/macro-for-word-2007-paste-special-gives-an-error/e7624781-d131-4629-832f-a59c9779fb6a?db=5&auth=1

suggests that that error message is because nothing was copied into the clipboard. The commenter suggested adding this code before the Selection.PasteSpecial command:

On Error Resume Next

This leads to no error message (5342) being displayed when the the macro is run but there is, in fact, text on the clipboard as ctrl-v or Edit->Paste special->Unformatted text both copy something, the first with formatting, the second without.


2016-02-27 12:48:18

Richard Ong

In Word 2003, I have achieved this "paste unformatted" feat in the past by recording a macro consisting of my going through the menu thus: Edit->Paste special->Unformatted text.

This yields a macro with this code:

Selection.PasteSpecial DataType:=wdPasteText

This has worked fine for months and months but for some reason it started pasting text WITH formatting. I don't remember doing anything to my settings. I ran "Detect and repair" under Help but that didn't help.

I found your entry here but your suggested code pastes nothing and I get the error window with this message:

"Run-time error '5342':

The specified data type is unavailable."

Ctrl-v pastes SOMETHING but it's formatted, of course.


2015-06-14 14:04:27

Charles Morford

This may be another of your tips that I can really use. I am writing a book in Word 2003. The 10 chapters of text are complete. I used a pre-formatted template provided by the publisher (CreateSpace). Now I have to complete my work to PDF to submit it to them. I would like to have as clean a copy as possible without loosing the necessary formatting. Will this tip work for me or do you have a better idea? Thank you in advance for your help.


2013-05-01 08:33:08

arnold ziffel

Great tip, got something along those lines that I need a macro for. 1)I have a word document that spans a full 80 char wide (only left 50 char used) and thus won't print the first 4 left char. 2) I need to change font type and size. 3) there are a lot of tables and paragragh formatting that I need to get get rid of but keep the text location . I have over 1500+ rtf type documents that I need to "convert" at one shot into a document that has the proper left printable margin. Can you help


2012-08-21 01:11:10

Shanker. K.Vee.

Hey Allen,

What about 'Cut, Copy, and Paste' options under 'Advanced' in 'Word Options'? Having a macro instead is anyway better?


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.