0
votes

I have an big .txt document imported in Word (2013 version btw). In the text I have the "paragraphs" formatted with several lines and "terminated" with a blank line.

In Word I would like do a semi automatic improvement of these "paragraphs" removing all but the last end-paragraph mark. I can select manually the groups of lines and run the macro/vba that clean the paragraph.

(I don't want an totally automatic function, nor change other than the loaded document)

Please see the attached image. You can see the Word end mark in each "line". I want to remove the mark in all the lines except the real last, thus getting one only paragraph with all the selected lines.

As an addon I like also clean also the excess of spaces (shown as .... in the image), thus change n spaces to only one.

I've tried some tips founded here (as this) but I think the mine is a different thing.

Thanks very much, and sorry my poor english.

several lines selected in order to clean an format a an paragraph

2
Of course the final cleaned paragraph must be formatted as this image farm9.staticflickr.com/8677/16689915356_f42d402ef5_o.pngGuillermo

2 Answers

1
votes

You can replace all paragraph marks "^p" with nothing "", and replace two/three " " (blank-spaces) with one " " using code given below.

Your document may also contain double paragraph marks i.e "^p^p". Replacing "^p^p" with "^p" first; will do the job.

Dim Mr As Range
Set Mr = ActiveDocument.Content
With Mr.Find
            .Wrap = wdFindContinue
            .Text = "^p"
            .Replacement.Text = ""
            .Execute Replace:=wdReplaceAll
End With
With Mr.Find
            .Wrap = wdFindContinue
            .Text = "   "
            .Replacement.Text = " "
            .Execute Replace:=wdReplaceAll
End With
With Mr.Find
            .Wrap = wdFindContinue
            .Text = "  "
            .Replacement.Text = " "
            .Execute Replace:=wdReplaceAll
End With
1
votes

Use the Find and Replace functionality in Word to replace two spaces with a single space. Keep doing this until it says no more occurrences were found.

To look for the paragraph marks, search for "^p" without the quotes. You can replace this with nothing or with a space.