by Allen Wyatt
(last updated August 20, 2016)
There may be times when you are working with a document when you have a need to remove extra paragraph marks. This is particularly true if you are working with an ASCII file or a file that may have originally been formatted with another word processor. This process of manually removing extra paragraph marks can be very time consuming.
If you find yourself in this situation, you may find this macro of interest. It removes extra paragraph marks from a document. When it is completed, there should not be even two paragraph marks in a row in your document.
Sub ReplacePara() Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting With Selection.Find .Text = "^p^p" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute While Selection.Find.Found Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.TypeBackspace Selection.MoveLeft Unit:=wdCharacter, Count:=2 Selection.Find.Execute Wend End Sub
There are two parts to this macro. The first part—which relies on the Selection.Find method—uses Word's built-in find and replace capabilities to find all instances of two paragraph marks in sequence. The macro doesn't replace the sequential paragraph marks; it simply finds them. Then the second part of the macro kicks in—using the Selection.Find.Found—property to delete the second of the two sequential paragraph marks.
The reason this approach is taken is because it leaves the formatting correct on the remaining paragraph mark. For instance, if the two sequential paragraph marks use different formatting from each other, the formatting of the first paragraph mark remains unchanged. If you simply replaced the sequential paragraph marks with a single paragraph mark, it is possible that you may not have the formatting exactly as you want when the replacing is finished.
Note that Selection.Find.Found is used as a "flag" for the While loop. This property reflects the status of the latest Find operation. If True then the search was successful; if False, then there was nothing found (and, therefore, nothing to change).
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (998) applies to Microsoft Word 2007, 2010, 2013, and 2016.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
When you type information into a document, what you type normally is inserted just the left of the insertion point. Word ...Discover More
Want to add an overline above a character or two in your document? There are several ways you can try, as described in this ...Discover More
It is not unusual to need to insert foreign characters (often called diacritical marks) as part of your typing. Word provides ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.