Create a new line after every sentence

D

DontKnow

Hi Guys,

What I am trying to do is:
Allow a new sentence after every fullstop. Basically run a macro that has
every sentence on a new line. Currently I have 4 or 5 pages of sentences
that are not on a single line per sentence as well there are carriage returns
throughout. This is what I currently have:

"The major responsibility of Signallers is to operate the signalling
equipment in order to ensurethe safety of the public and the safe and
efficient passage of trains in the area under their control. Signallers
monitor a signalling display so that they are aware of all train movements
and any events happening in their area of control. This includes any areas
where they have no control of the signalling equipment, but the trains are
under their supervision. The Signaller is also responsible for compiling a
train register book, which includes entries for the following information."

How can I set this up via a macro: Notice how every sentence is set on a new
line there are no carriage returns within each sentence.

The major responsibility of Signallers is to operate the signalling
equipment in order to ensurethe safety of the public and the safe and
efficient passage of trains in the area under their control.

This includes any areas where they have no control of the signalling
equipment, but the trains are under their supervision.

The Signaller is also responsible for compiling a train register book, which
includes entries for the following information."

Thankyou in advance for your invaluable help!!

Cheers,
 
G

Gordon Bentley-Mix

I'm not sure that a macro is really required. Surely find and replace will do
the job. If you search for ". " (fullstop followed by a single space) and
replace it with ".^p" (fullstop, Shift+6, the letter "p" - "^p" being the
'find and replace symbol' for a paragraph mark), this should get you pretty
close.

The only problems might be with instances where the fullstop is followed by
two spaces, but then you could follow up by searching for "^p " (paragraph
mark followed by a single space) and replacing it with "^p" (just the
paragraph mark). You might have to do this last step a couple of times to
accommodate the possibility of a fullstop followed by more than 2 spaces.

If you really want to automate this, you could write a macro to drive the
find and replace, but if it's only one or two documents, I'm not sure it's
worth it. However, if you do want a macro, I'd recommend starting with the
macro recorder to get the basic code and then tweaking as appropriate.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

David Horowitz

Hi - I agree with Gordon on all counts. I think the poster mentioned s/he
currently has paragraph marks as the end of each line and therefore might
need them attended to first. I broke it down into two steps below, and may
require the third Gordon mentioned in case of double spaces. I also provide
VBA at the end.
Steps:
1. Change all paragraph marks to spaces:
a. Edit > Replace
b. Find What = ^p ("^p")
c. Replace With = a space (" ")
d. Replace All
2. Change all period/spaces to period/paragraph marks:
a. Edit > Replace
b. Find What = period and a space (". ")
c. Replace With = .^p (".^p")
d. Replace All
If you want to do this via VBA, you could record the macro using Tools >
Macro > Record, and you'll get something pretty complicated.
But you can accomplish the same with this routine:
Sub CleanupText()
Selection.Find.Execute FindText:="^p", ReplaceWith:=" ",
Replace:=wdReplaceAll
Selection.Find.Execute FindText:=". ", ReplaceWith:=".^p",
Replace:=wdReplaceAll
End Sub
Hope this helps.
David
Lead Technologist
Soundside Inc.
www.soundside.biz
 
G

Gordon Bentley-Mix

Very nice David. Thanks for the assist!
--
Cheers!

Gordon Bentley-Mix
Word MVP

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

DontKnow

Excellent Guys,

Thank you both!!

I think i shall utilise the VBA via a macro!!

Cheers
 
F

fumei via OfficeKB.com

I am not so sure about this.

The OP originally writes:

"Currently I have 4 or 5 pages of sentences that are not on a single line per
sentence as well there are carriage returns throughout."

Yet also writes:

"Notice how every sentence is set on a new line there are no carriage returns
within each sentence."

On one hand there are carriage returns throughout, on the other there are no
carriage returns.

From looking at the example text, it sure seems to me that the "lines" are
not terminated by a ^p (paragraph mark), but by a ^l (manual line break)

Further, regarding one v.s. two spaces between sentences, this can easily be
handled by using Sentences itself.

I agree that using Find & Replace is likely faster, but here is a possible
alternative.

Sub Sentence2Paragraph()
Dim j As Long
' replace all manual line breaks with nothing
ActiveDocument.Content = _
Replace(ActiveDocument.Content, Chr(11), "")

' add a paragraph mark to each sentence, thus
' making it a paragraph
For j = 1 To ActiveDocument.Sentences.Count - 1
ActiveDocument.Sentences(j).Text = _
ActiveDocument.Sentences(j).Text & vbCrLf
Next
End Sub

This deals with Sentences, so it does not matter if there is one, or two, or
five spaces between them.
David said:
Best of luck!
Excellent Guys,
[quoted text clipped - 88 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top