1

I have used some of these wildcards in Replace from other threads on here with good results so far. But right now I am having difficulties with what appears to be an Enter key being pressed (newline) at each line, and the document is very long. The document itself is a .txt generated subtitles from Youtube video. I am trying to replace that newline after each 5-6 words.

I have also tried most of the Special Replace options down the box in the Replace menu and some other tweaks I have read about on here, but so far only managed to concatenate all the letters together.

I need to be able to format it as a normal text, i.e. like this post.

The file looks something like the following.

because a ponzi scheme doesn't generate

any wealth itself

it must constantly bring in larger and

larger groups of investors to keep

functioning

eventually no more new investors can be

found

or large numbers of previous investors

ZygD
  • 2,459
  • 12
  • 26
  • 43
Tony
  • 11
  • 1
  • See these two Word MVP pages: http://wordfaqs.ssbarnhill.com/CleanWebText.htm https://gregmaxey.com/word_tip_pages/cleanup_text.html – Charles Kenyon Mar 10 '21 at 13:48

1 Answers1

1

I'm not clear whether you want to eliminate all carriage returns or just extra ones between paragraphs. Below is a script that will eliminate extra ones, but the carriage return at the end of the paragraph stays.

Give us an update after you run it against your file.

Sub RemoveEmptyParagraphs()
    Dim rng As Word.Range
    Set rng = ActiveDocument.Content
    'eliminate empty paragraphs
    With rng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "^13{2,}" ' look for 2
        .Replacement.Text = "^p" 'replace with 1, this is 508 acceptable
        .Forward = True
        .Wrap = Word.WdFindWrap.wdFindStop
        .Format = False
        .MatchWildcards = True
    End With
    rng.Find.Execute Replace:=Word.WdReplace.wdReplaceAll
    rng.Find.ClearFormatting
    rng.Find.Replacement.ClearFormatting
End Sub
Rich Michaels
  • 2,841
  • 2
  • 11
  • 20