Fix broken sentences
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Fix broken sentences
As you can see from the picture, I have a document with broken sentences. In #1, the 13 should not be on its own line, along with #2, Nehemiah should not be on its own line. How can this be fixed?
Before After
I. Introduction
A. Grow and become strong in your faith
1. That's why we go through the Bible "precept upon precept, line upon line" (see Isaiah 28:10,
13)
2. Nehemiah and Ezra read from the law and then gave the sense (see
Nehemiah 8:8)
3. Verse by verse, chapter by chapter
Before After
I. Introduction
A. Grow and become strong in your faith
1. That's why we go through the Bible "precept upon precept, line upon line" (see Isaiah 28:10,
13)
2. Nehemiah and Ezra read from the law and then gave the sense (see
Nehemiah 8:8)
3. Verse by verse, chapter by chapter
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Fix broken sentences
Try this macro. Test it on a copy of the document, please!
Code: Select all
Sub FixSentences()
Dim i As Long
Dim rng As Range
Application.ScreenUpdating = False
For i = ActiveDocument.Paragraphs.Count To 2 Step -1
Set rng = ActiveDocument.Paragraphs(i).Range
If Not rng.Text Like "?. *" Then
rng.Collapse
rng.MoveStart Unit:=wdCharacter, Count:=-1
rng.Text = " "
End If
Next i
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Re: Fix broken sentences
Hi Hans,
Yes, I'm testing on a very small portion. The end will be most likely be well over 100 pages. This macro works partially. It cleans up those orphan sentences, but when it comes to some paragraphs starting with i, ii, iii, iv, etc, it wraps those in one long paragraph.
Maybe in the end, I just don't know the right process here. I want to take this PDF, copy it to Word and retain the paragraph style. Is there a better way to do this?
Yes, I'm testing on a very small portion. The end will be most likely be well over 100 pages. This macro works partially. It cleans up those orphan sentences, but when it comes to some paragraphs starting with i, ii, iii, iv, etc, it wraps those in one long paragraph.
Maybe in the end, I just don't know the right process here. I want to take this PDF, copy it to Word and retain the paragraph style. Is there a better way to do this?
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Fix broken sentences
Try to get hold of the original document instead of the PDF.
If that's not possible, I'd stick with what you have. Trying to fix it will be hell...
If that's not possible, I'd stick with what you have. Trying to fix it will be hell...
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Re: Fix broken sentences
Got it. There isn't any way to get the original PDF. Thanks Hans as always.
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Fix broken sentences
Hello Gailb. I have over the years developed two applications that clean document text, including resurrecting sentences (and paragraphs) from broken text.
The first is DOCumentCLEanser which was originally used to batch-process thousands of WordPerfect 5.1(DOS) files and neaten them up, but has found use in cleaning text files printed from PDF files. DocCle is rules-driven (so you basically program in its limited but powerful language).
The Second is UNDER-the-hood, which was inspired by Woody Leonhard 's book "The Underground Guide to Word for Windows". This program contains 587 macros in 24 modules. I have attached a TXT list of 55 macros in one of these modules "modTextChange" for your edification.
If you would like to inspect or install the code please let me know.
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
He who plants a seed, plants life.
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Re: Fix broken sentences
Hi Chris and thank you for your time. I would absolutely love to install the code. Anything that will help me get further along down the road.
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Fix broken sentences
Hi Gail.
(1) Is the attached Word2003 document a fair representation that I can use as a testbed?
(2) Later today I will put together a package that you can download and play with.
The package will, I think, have a working example of DoCle and results of using Under.
Since the package will have the code, you can, if you prefer, cannibalise the VBA code.
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
He who plants a seed, plants life.
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Re: Fix broken sentences
Yes, that is an accurate example.
-
- 5StarLounger
- Posts: 626
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Fix broken sentences
Suzanne Barnhill has a page on this. http://wordfaqs.ssbarnhill.com/CleanWebText.htm
Greg Maxey has an Add-In (free) that you might want to use. https://gregmaxey.com/word_tip_pages/cleanup_text.html
Converted text is often a pain to edit.
I will usually use paste special and paste as plain text. Then apply the formatting using styles in Word.
But, that's just how I am.
Greg Maxey has an Add-In (free) that you might want to use. https://gregmaxey.com/word_tip_pages/cleanup_text.html
Converted text is often a pain to edit.
I will usually use paste special and paste as plain text. Then apply the formatting using styles in Word.
But, that's just how I am.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- 5StarLounger
- Posts: 626
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Fix broken sentences
Hi Chris,ChrisGreaves wrote: ↑01 Feb 2021, 12:09***
The Second is UNDER-the-hood, which was inspired by Woody Leonhard 's book "The Underground Guide to Word for Windows". This program contains 587 macros in 24 modules. I have attached a TXT list of 55 macros in one of these modules "modTextChange" for your edification.
If you would like to inspect or install the code please let me know.
Cheers
Chris
I got my start with vba with Woody's "Word 97 Annoyances." That was probably an updated version.
I am a great fan.
Last edited by Charles Kenyon on 02 Feb 2021, 20:52, edited 1 time in total.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Fix broken sentences
Hi Gail.
You can download a 1 MB file from chrisgreaves.com/Downloads/20210202_1645.zip.
The package includes a document ReadMe.doc that you can read before making a decision whether this approach might work for you.
I realised last night that my sample 5-page "Mark 1_1-31 - Detailed Notes.doc" is NOT an accurate representation of your PDF file, because I used select All and then copied and pasted the data as text.
That said, regardless of how you reduce that PDF to text, I believe that DoCleanser can do the job, once we have worked out the rules.
I have provided a small RulesTable_working.doc and used two of the rules to effect changes to the text document so that you can see that changes can be automated.
Cheers
Chris
He who plants a seed, plants life.
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Re: Fix broken sentences
Thanks Chris and Charles for your time. I will look into all of these tips and ideas.
Last edited by gailb on 03 Feb 2021, 13:02, edited 1 time in total.
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Fix broken sentences
Mister Woody Leonhard has a lot to answer forCharles Kenyon wrote: ↑02 Feb 2021, 20:17I got my start with vba with Woody's "Word 97 Annoyances." That was probably an updated version. I am a great fan.
He led me into a life of crime.
I not only stole a lot of his Word6 Macro6 code, but have habitually used one of his opening lines "Let's make this book pay for itself right off the bat" (I paraphrase) as an approach to the design of training courses.
Cheers
Chris
He who plants a seed, plants life.
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Re: Fix broken sentences
Hi Hans,
In post #2, how can that be changed to only apply to the selected text?
In post #2, how can that be changed to only apply to the selected text?
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Fix broken sentences
Simples: change ActiveDocument to Selection:
Code: Select all
Sub FixSentencesInSelection()
Dim i As Long
Dim rng As Range
Application.ScreenUpdating = False
For i = Selection.Paragraphs.Count To 2 Step -1
Set rng = Selection.Paragraphs(i).Range
If Not rng.Text Like "?. *" Then
rng.Collapse
rng.MoveStart Unit:=wdCharacter, Count:=-1
rng.Text = " "
End If
Next i
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 254
- Joined: 09 May 2020, 14:00
Re: Fix broken sentences
Perfect, thank you.