As I do some clean-up to some documents, one of the sections that starts with A4 has some paragraphs that got separated.
From the example below, there are four paragraphs, but the second paragraph has been separated to the next line making five lines. How can I get the second paragraph to be all in one line?
Before
A4.1. A glittering gem is not enough.
A4.2. I was very proud of my nickname throughout high school, but today
I couldn’t be any different to what my nickname was.
A4.2.1. The quick brown fox jumps over the lazy dog.
A4.2.2. The waves were crashing on the shore; it was a lovely sight.
After
A4.1. A glittering gem is not enough.
A4.2. I was very proud of my nickname throughout high school, but today I couldn’t be any different to what my nickname was.
A4.2.1. The quick brown fox jumps over the lazy dog.
A4.2.2. The waves were crashing on the shore; it was a lovely sight.
Collapse two lines into one
-
- Administrator
- Posts: 78386
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Collapse two lines into one
Does this macro do what you want? (Select the text before running it)
Code: Select all
Sub MergeParagraphs()
Dim i As Long
Dim n As Long
Application.ScreenUpdating = False
For i = Selection.Paragraphs.Count To 1 Step -1
If Left(Selection.Paragraphs(i).Range.Text, 3) <> "A4." Then
n = Selection.Paragraphs(i).Range.Start
ActiveDocument.Range(n - 1, n).Text = " "
End If
Next i
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 91
- Joined: 02 Sep 2018, 23:12
Re: Collapse two lines into one
Hi Hans,
Yes, this works perfectly.
Yes, this works perfectly.
-
- PlutoniumLounger
- Posts: 15585
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Collapse two lines into one
Hi SmallFry
Pleas see also the macro "GlueLetters" in the attached text, part of my "TextChange" module, various options to glue lines (or paragraphs) together.
Cheers
Chris
Pleas see also the macro "GlueLetters" in the attached text, part of my "TextChange" module, various options to glue lines (or paragraphs) together.
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle
-
- StarLounger
- Posts: 91
- Joined: 02 Sep 2018, 23:12
Re: Collapse two lines into one
Hi Chris and thank you for the reply,
I copied out this text file code, but it seems to be missing something.
I see as I run it, it returns a debug to the line
Sub or Function not defined
I suppose this could cause a problem also!
I copied out this text file code, but it seems to be missing something.
I see as I run it, it returns a debug to the line
Code: Select all
Set rng = rngGetSel(Selection)
I suppose this could cause a problem also!
Code: Select all
Call ClearFindReplaceFormatting(Selection)
-
- Administrator
- Posts: 78386
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Collapse two lines into one
Chris has a habit of posting code that relies on his extensive library of utilities, without posting the necessary utilities...
Best wishes,
Hans
Hans
-
- PlutoniumLounger
- Posts: 15585
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Collapse two lines into one
Please accept my apologies. I posted the code to give you an idea, from a working function, or what might be done.SmallFry wrote:Set rng = rngGetSel(Selection)
I have attached a copy of the rngGetSel function from my library UW.DOT. Drag the commented TEST macro outside the function, decomment, and run the TEST after selecting a chunk of text in an active document. The TEST macro should MsgBox the selected text.
You can download a copy of UW.dot in the Indxr package whose link(s) are provided in this post. If the DOWNLOAD fails PM me with an email address and I will attach a copy of UW.dot to a reply by email.
If you want to explore more line-joining code I have attached a module from my Under.dot, although some of those procedures too might fail to execute without UW.dot.
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle
-
- PlutoniumLounger
- Posts: 15585
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Collapse two lines into one
True. Partly because of the Lounge's 256Kb limit, but also because I figured I had posted enough copies of UW.dot to last a lifetime!HansV wrote:Chris has a habit of posting code that relies on his extensive library of utilities, without posting the necessary utilities...
Well, also because I am split between providing an immediate fix, and allowing someone who is learning time to learen.
Time for another poll, I think
Cheers
Chris
There's nothing heavier than an empty water bottle
-
- StarLounger
- Posts: 91
- Joined: 02 Sep 2018, 23:12
Re: Collapse two lines into one
And truly appreciated Chris. I will do my best to learn from what you have provided.Well, also because I am split between providing an immediate fix, and allowing someone who is learning time to learn.