View Single Post
 
Old 11-12-2021, 08:50 PM
John O'Rourke John O'Rourke is offline Windows 10 Office 2019
Novice
 
Join Date: Nov 2021
Posts: 6
John O'Rourke is on a distinguished road
Default Separate paragraphs into short chunks to make it readable on a cell phonoe

Thanks for trying but the code just takes forever to run. It is proceeding a character at a time until it reaches 500 characters. I have written another version that breaks up the paragraphs into 300 characters or more unless the remaining characters in the paragraph are less than 400 ( so you don't end a paragraph with a small sentence) at the end. It uses the 2 for each clauses. Here is the code. It does a fair job but I think that my tc(total characters) ts(total sentences) are not properly aligned with the actual sentences and characters. This leaves a small sentence internally (bug: probably relates to inserting a vbcr that still has more characters/sentences to include in the paragraph. This relates to the fact that the sentence and character count changes when you insert a paragraph mark in the middle of the paragraph, so occasionally I get a short sentence within the group of paragraphs.
It has the virtue of not crashing and running quickly. See if you can improve on it. Also, I don't want it to insert a blank paragraph at the very end.

Sub insertp()
Dim p As Paragraph

Dim ts As Long
Dim tc As Long
Dim i As Long
Dim doc As Document

Set doc = ActiveDocument
Application.ScreenUpdating = Falsec


For Each p In doc.Paragraphs
ts = 0
tc = 0
For Each sn In p.Range.Sentences
ts = ts + 1
tc = tc + Len(sn)
If p.Range.Characters.Count < 400 Then
Exit For
End If

If tc >= 300 And ts < p.Range.Sentences.Count Then
p.Range.Sentences(ts).InsertAfter vbCr
tc = 0
ts = 0
End If

Next
Next

Application.ScreenUpdating = True

End Sub
thanks for any help.

Last edited by John O'Rourke; 11-13-2021 at 12:40 PM.
Reply With Quote