Share via

Separating Text by Character Count Part 2

Anonymous
2015-06-19T19:02:31+00:00

I have a large block of text and I need to separate it by character count. An example would be, every 25 characters (No spaces) I want to go to the next line. I also do not want to split words up. For example if the text read

"The quick Brown Fox Jumps over the lazy dog and peter piper picked some pickled peppers."

it would now be

"The quick Brown Fox Jumps over

the lazy dog and peter piper

picked some pickled peppers."

Thanks for all the help!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Paul Edstein 82,861 Reputation points Volunteer Moderator
2015-06-20T05:18:17+00:00

I did. it made the paragraph break at the first space after the 25th character

Which is essentially what your first post in this thread depicts - except that:

"The quick Brown Fox Jumps over

is actually 31 characters, which is more than even the Find/Replace would have given.

I don't believe you can use Find/Replace to limit word-based strings to a given number of characters. You can do so, however, with a macro such as:

Sub Demo()

Application.ScreenUpdating = False

With ActiveDocument.Range

  With .Find

    .ClearFormatting

    .Replacement.ClearFormatting

    .Text = "<*{25}>"

    .Replacement.Text = ""

    .Forward = True

    .Wrap = wdFindStop

    .Format = False

    .MatchWildcards = True

    .Execute

  End With

  Do While .Find.Found

    While .Characters.Count > 25

      .MoveEnd wdWord, -1

    Wend

    .InsertAfter Chr(11)

    .Collapse wdCollapseEnd

    .Find.Execute

  Loop

End With

Application.ScreenUpdating = True

End Sub

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-06-20T04:35:26+00:00

    I did. it made the paragraph break at the first space after the 25th character and I cannot exceed 25 characters. Is it possible to make the paragraph break at the first space before the 25th character?

    Was this answer helpful?

    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2015-06-20T00:25:14+00:00

    Did you try the Find/Replace expression I posted in your other thread?

    Was this answer helpful?

    0 comments No comments