Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #26  
Old 11-12-2021, 08:50 PM
John O'Rourke John O'Rourke is offline How to insert paragraph character after every 500 characters? Windows 10 How to insert paragraph character after every 500 characters? 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
 

Tags
paragraph character



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert paragraph character after every 500 characters? Restricting paragraph styles without restricting character styles Red Pill Word 5 05-25-2012 01:06 PM
character set bobster Word 0 06-07-2011 10:17 AM
How to insert paragraph character after every 500 characters? tab key arrows first character 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft