Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Strip Trailing Spaces.

Strip Trailing Spaces

by Allen Wyatt
(last updated February 28, 2015)


Maybe I'm one of those compulsive-obsessive types, but I always go through my documents to make sure there are no trailing spaces at the end of a paragraph. This makes the document neater and smaller. If you format ASCII files or documents you receive from other people, you will need to search for trailing spaces and remove them as you format the file for Word. The following macro, StripSpaces, takes out all spaces before paragraph marks and manual line breaks throughout your document.

Sub StripSpaces()
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
        .Text = " ^p"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchWholeWord = False
        .MatchWildcards = False
    End With
    While Selection.Find.Found
        Selection.HomeKey Unit:=wdStory
        Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.Text = " ^l"
    Selection.Find.Replacement.Text = "^l"
    While Selection.Find.Found
        Selection.HomeKey Unit:=wdStory
        Selection.Find.Execute Replace:=wdReplaceAll
End Sub

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13376) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Strip Trailing Spaces.

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. ...


Relative References when Recording Macros

When you record a macro, make sure that you know how Excel is recording your cell movements. This tip explains the ...

Discover More

Protect Your Document Templates

If you want to protect your templates from accidental changes, the best way to do so is by using Windows instead of Word. ...

Discover More

Erroneous Out of Space Messages

While they are less common these days than they used to be, you still might see an error that indicates Word is out of ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Selecting the Entire Document with the Mouse

Want a quick way to select your entire document without taking your hand off of the mouse? Try clicking away using the ...

Discover More

Smart Quote after Em Dash Faces Wrong Direction

When using smart quotes in your typing, Word tries its best to figure out which way the quote you just typed should face. ...

Discover More

Selecting Sentences

Need to select an entire sentence at once? You can do so by creating a short macro that does the task for you, or you can ...

Discover More

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

View most recent newsletter.


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 1 + 8?

2017-07-26 12:34:58

Andres Reyes

I am using Word 2013 (15.0.4701.1001) MSO (15.0.4701.1000) 32-bit. When I use the macro, there is a lot of fast blinking of the first page, then a pause for a second or so and then blinking again. This sequence repeats a many times. Then the blinking stops, but the 'busy' circle shaped mouse pointer stays on. I let it wait for over an hour and then clicked on the window. The window became 'dim'. Task manager reported Word as not responding. When I click on the 'x' in the window I get the not responding popup to wait of restart.

The document is 86 pages long and contains many tables.

I copied and pasted the macro, so I know that it is what you published.

Any ideas?

2015-03-04 16:32:22


Use '^w^p' to clear all "white space" prior to a paragraph. This will get 1 or 2 or more spaces, as well as any tabs that may be there. Use '^w^l" to clear out the white space prior to a manual line break. A macro is unnecessary and I find that trying to figure out where to store the is more trouble than it is worth in many cases.

2015-03-03 10:18:57


Lisa, you are right, except the idea is to strip trailing spaces, as this is what the article is about. I just thought that a paragraph can end with more than one space, so I added the suggestion to repeat the command several times.

2015-03-02 08:33:17

Lisa Herider

Damear, I believe your replace dialogue will only get the multiple spaces before a paragraph return. Using the same approach just search for a double spaceband (space space) and replace it with a single. Again, you will need to do this multiple times until 'Replacements made:' shows 0. Using this method finds all instances of multiple spaces regardless of what's before or after them.

2015-03-01 08:20:43


Or just press Ctrl-H for Find and Replace dialog, then enter ' ^p' (space, caret, p) in the Find What field and '^p' (same as above, but without space) in the Replace field. Then press Replace All button. Sometimes this step has to be repeated several times if there are multiple trailing spaces in some paragraphs. Watch the dialog window that pops up stating 'Replacements made:' until it shows 0.

This Site

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

Newest Tips

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.