Word Tips

How to Batch Replace Soft Returns in Microsoft Word Documents

How to Batch Replace Soft Returns in Microsoft Word Documents

I know, it keeps you awake at night, too!

Ha, ha…

But, if that’s what floats your boat–and how to batch replace soft returns in multiple Word documents is on your mind–then fantastic.

Fortunately, there is a quick and easy way of doing this.

Caveat: there are some wonderfully fantastic people out there who are macro-geniuses. They’re far better than I am and, as such (and where possible) find them. They will make your life a whole lot easier.

I first published this as an answer to a Quora question in May 2018, but they deleted it (don’t know why):

So, reposting here for those purposes…

Here’s the video:

Note: all the files must be in the same folder.


Original code:

The link to the original code is here.

The modified code I used is here:

Sub FindReplaceLineBreaks()
Dim file
Dim path As String

' this code taken from Running a macro on all files in a folder - Tips for Module Creation
' Path to your folder. MY folder is listed below. I bet yours is different.
' make SURE you include the terminating "\"

'YOU MUST EDIT THIS:
path = "C:\Users\name\Test folder\"

'Change this file extension to the file you are opening. Russ edit: I changed this to .docx, as you can see.

'YOU MUST EDIT THIS.
file = Dir(path & "*.docx")

Do While file <> ""
Documents.Open FileName:=path & file

' Russ edit: below is the code to find as soft return and replace it with a hard return

'This is the find and replace code - part 1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

'Russ edit: this is the code that does the 'find soft return' (^l) and then replace it with a 'hard return' (^p)

With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True

End With

'this line tells it to replace all instances that it finds.
Selection.Find.Execute Replace:=wdReplaceAll

' Saves the file and then closes it
ActiveDocument.Save
ActiveDocument.Close

' this tells the file to loop to the next Directory
file = Dir()
Loop

End Sub

If you have any problems, watch the video again. 😉


Learn Microsoft Word for FREE…

If you want to learn a little more about how to use Microsoft Word properly, then check out my FREEA Quick Start to Microsoft Word‘ course.

The link is here:

A quick start to Microsoft Word graphic

Leave a Reply