![]() |
#26
|
|||
|
|||
![]()
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. |
Tags |
paragraph character |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Red Pill | Word | 5 | 05-25-2012 01:06 PM |
character set | bobster | Word | 0 | 06-07-2011 10:17 AM |
![]() |
carolinason | Word | 6 | 10-30-2010 06:45 PM |
Junk characters (box-like characters) in Word file | Sashikala | Word | 1 | 04-20-2010 02:03 PM |
Character style stripped while applying paragraph style | sams_gates | Word | 0 | 08-29-2009 02:03 AM |