
Tips.Net > WordTips Home > Editing > Strip Trailing Spaces
Summary: A common nuisance in documents is unnecessary trailing spaces at the end of paragraphs. This tip provides a macro that makes quick work of those spaces, removing them from the document completely. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
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 line. This makes the document neater and smaller. If you format ASCII files, you will need to search for trailing spaces, and remove them, as you format the file for Word. The following macro, StripSpaces, will take out all spaces before paragraph marks and manual line breaks throughout your document.
Sub StripSpaces()
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " ^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWholeWord = False
.MatchWildcards = False
End With
Selection.Find.Execute
While Selection.Find.Found
Selection.HomeKey Unit:=wdStory
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute
Wend
Selection.Find.Text = " ^l"
Selection.Find.Replacement.Text = "^l"
Selection.Find.Execute
While Selection.Find.Found
Selection.HomeKey Unit:=wdStory
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute
Wend
End Sub
Tip #969 applies to Microsoft Word versions: 97 2000 2002 2003
Find and Replace Almost Anything! Learn the ins and outs of the powerful search engines available in Word. Learn to search for and replace text, formatting, graphics, and special characters the easy way with WordTips: Find and Replace.
Learn to search for and replace text, formatting, graphics, and special characters the easy way with WordTips: Find and Replace. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips