Automatically removing Enter key

C

Clarendon

Removing Enter from the document

I have a long list of lines separated by Enter key but have to join every
two lines together by removing the Enter between them. For instance, I need
to join lines 1, 2 together and lines 3, 4 together.

1. you. All screensavers come with a free 7 day trial.
2. Please make sure any products you purchase work properly on your system
before
3. you. All screensavers come with a free 7 day trial.
4. Please make sure any products you purchase work properly on your system
before

I have thousands of lines and is there any way to do this automatically? I
know I can remove word spaces by find and replace. Can this remove enter keys
as well, or are there other ways?

thanks.
 
P

Peter T. Daniels

Find/Replace (Ctrl-H) > More > Special > Paragraph Mark (you'll see
"^p" in your Find What? box, and you could simply type that).

If there's a space before the paragraph mark (what you call "enter
key"), then put nothing in the Replace box. If not, type a space in
the Replace box.

Click "Replace All."

HOWEVER, If lines 1 and 2 (in your example below) really have no space
between them, and you want them to end up as separate paragraphs, then
you'll have to go through and add a _second_ paragraph enter at each
such point.

After you do that, do a Find on ^p^p and Replace with something that
doesn't occur elsewhere in the text (such as ^l [small L]), then Find/
Replace ^p with space or nothing as above, and finally Find/Replace ^l
with ^p.
 
G

Greg Maxey

Clarendon,

It sounds like you have a mess on your hands. If you follow Peter
Daniel's advise you will have a bigger mess. Despite the efforts of
several people to convince Peter stay within his very limited range of
expertise, he will often try to answer questions that he does not
understand or when he as no concept of the correct answer. I don't
know why he does this. I think he is an aspiring Word MVP and tries
to bloat his post count.

If I understand your objective correctly you want your example:

1. you. All screensavers come with a free 7 day trial.
2. Please make sure any products you purchase work properly on your
system
before
3. you. All screensavers come with a free 7 day trial.
4. Please make sure any products you purchase work properly on your
system
before

To look like this;

1. you. All screensavers come with a free 7 day trial. 2. Please make
sure any products you purchase work properly on your system before
3. you. All screensavers come with a free 7 day trial. 4. Please make
sure any products you purchase work properly on your system before

You can easily do this with a macro:


Sub ClarendonsNeedMeetsTheHammer()
Dim i As Long
Dim Count As Long
Count = ActiveDocument.Paragraphs.Count \ 2
For i = 1 To Count
ActiveDocument.Paragraphs(i).Range.Characters.Last = Chr(32)
Next i
End Sub
 
G

Greg Maxey

Peter,

Remember goals and objective statement 2:

2. Post when and wherever you like, but stay in your range of expertise.
Always be open to the ideas and suggestion of others. If you venture
outside your range then try to be correct.
Find/Replace (Ctrl-H) > More > Special > Paragraph Mark (you'll see
"^p" in your Find What? box, and you could simply type that).

If there's a space before the paragraph mark (what you call "enter
key"), then put nothing in the Replace box. If not, type a space in
the Replace box.

Click "Replace All."

HOWEVER, If lines 1 and 2 (in your example below) really have no space
between them, and you want them to end up as separate paragraphs, then
you'll have to go through and add a _second_ paragraph enter at each
such point.

After you do that, do a Find on ^p^p and Replace with something that
doesn't occur elsewhere in the text (such as ^l [small L]), then Find/
Replace ^p with space or nothing as above, and finally Find/Replace ^l
with ^p.

Removing Enter from the document

I have a long list of lines separated by Enter key but have to join
every two lines together by removing the Enter between them. For
instance, I need to join lines 1, 2 together and lines 3, 4 together.

1. you. All screensavers come with a free 7 day trial.
2. Please make sure any products you purchase work properly on your
system before
3. you. All screensavers come with a free 7 day trial.
4. Please make sure any products you purchase work properly on your
system before

I have thousands of lines and is there any way to do this
automatically? I know I can remove word spaces by find and replace.
Can this remove enter keys as well, or are there other ways?

thanks.

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR
 
P

Peter T. Daniels

Clarendon,

Greg Maxey is very good at creating macros, and a person who only has
a hammer sees every problem as a nail. As you can see from his other
message, he has become obsessed with me and the solutions I proffer
that are different from the ones he thinks best.

The Find/Replace paragraph marks procedure I described has worked for
me on many, many occasions.
 
G

Greg Maxey

Peter,

What Greg Maxey is is, how he uses a hammer, or his obsesions are not the
issue here. The issue is once again you have posted gibberish and it is not
a solution to the problem described.

The problem that Clarendon decribed is he has thousands of paragraph pairs
that he wants to combine into single paragraphs.:

One
Two
Three
Four

becomes

One Two
Three Four

He does not want to create one big giant paragraph as your first suggestion
would do.

One two three four.

Nor does he want to spend the rest of his life manually adapting his
document.

Clarendon,

Greg Maxey is very good at creating macros, and a person who only has
a hammer sees every problem as a nail. As you can see from his other
message, he has become obsessed with me and the solutions I proffer
that are different from the ones he thinks best.

The Find/Replace paragraph marks procedure I described has worked for
me on many, many occasions.

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR
 
G

Greg Maxey

Removing Enter from the document

I have a long list of lines separated by Enter key but have to join every
two lines together by removing the Enter between them. For instance, I need
to join lines 1, 2 together and lines 3, 4 together.

1. you. All screensavers come with a free 7 day trial.
2.  Please make sure any products you purchase work properly on your system
before
3. you. All screensavers come with a free 7 day trial.
4. Please make sure any products you purchase work properly on your system
before

I have thousands of lines and is there any way to do this automatically? I
know I can remove word spaces by find and replace. Can this remove enter keys
as well, or are there other ways?

thanks.

Clarendon,

You have been provided a cockamamie scheme for making a mess out of
your document and a macro solution that should take care of it in a
few seconds. Please choose between the options provided as you see
fit.

In fairness to Mr. Daniels, If you don't want to use a macro solution
then if you open the Replace dialog and type ^p in Find what and a
space " " in replace with and then use Find Next and Repace commands
to find and replace only the paragraph mark between the pairs then you
could cycle through the thousands of pairs one at a time and perhaps
save yourself some time.

Good luck.
 
P

Peter T. Daniels

Greg,

You have made a literalist assumption that the example put into the
original posting is representative of the entire text.

If the entire text is indeed sets of four lines that are to be
combined into two paragraphs, then your solution will work as well as
mine.

If it isn't, then it won't.

(Since the example text is the same words stated twice, it's unlikely
that it's an actual four-line slice of the original.)
 
C

Clarendon

Hi, Greg.

That's exactly what I need done. This must be a programming language in
Visual Basic. I've never tried macro, but i can try. But I have some
complication here. The lines are organized in the outline view under
different headings (just heading 1):

Heading
A
A'
B
B'
Heading
C
C'
D
D'

I want the headings to remain as they are, and just want the lines of the
same letter to be merged into one line under the headings. Also want the
paragraph mark to be changed into nothing rather than a space. Is this also
possible with macro?

Thanks.
 
G

Greg Maxey

Clarendon,

It is Visual Basic for Applications VBA and can be run straight from your
Word application. See: http://www.gmayor.com/installing_macro.htm

It gets a bit more complicated of course in view of your new conditions. I
tested the code below on a document formatted as follows:

Heading1
A
A
B
B
Heading 1
C
C
D
D
E
E
Heading 1
F
F
G
G

The result is:

Heading 1
AA
BB
Heading 1
CC
DD
EE
Heading 1
FF
GG

Sub ClarendonsNeedMeetsTheHammer()
Dim oRng As Range
Dim oTempRng As Range
Dim i As Long
'Set a Dummy trailing Header
ActiveDocument.Range.InsertAfter vbCr & "Dummy Heading" & vbCr
ActiveDocument.Paragraphs.Last.Previous.Style = "Heading 1"
Set oRng = ActiveDocument.Content
With oRng.Find
'Look for the Heading 1 text on execute
.Style = "Heading 1"
.Wrap = wdFindStop
While .Execute
'Collapse oRng to end of found Heading 1 text
oRng.Collapse wdCollapseEnd
'Set a temporary range that starts at end of Heading 1 text
Set oTempRng = oRng.Duplicate
'Look for next Heading 1 text on execute
.Execute
'Collapse oRng to start of Heading 1 text
oRng.Collapse wdCollapseStart
'Define temporary range that ends where Heading 1 text starts
oTempRng.End = oRng.End
'You have now bounded the paragraphs between two Heading 1 paragraphs
For i = 1 To oTempRng.Paragraphs.Count \ 2
oTempRng.Paragraphs(i).Range.Characters.Last.Delete
Next i
Wend
End With
'Delete dummy trailing header
ActiveDocument.Paragraphs.Last.Range.Delete
ActiveDocument.Paragraphs.Last.Range.Delete
End Sub


--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
 
G

Greg Maxey

Peter,

Why do you post here? If it is to help other people then please stop as you
only hinder and confuse whenevever you venture out of you very limited,
specialized area of expertise.

I did not assume anything. I read the man's question and then provided a
solution that addressed his stated need. Maybe Clarendon's "That's exactly
what I need done" has convinced you. Unless of course you intend to start
arguing with him about what he wants done.

Have you even tried your ridiculous suggestion? The only thing is does is
make one long paragraph out of all the paragraphs in the document. If you
refuse to test it and see for yourself then at least think about it. You
are finding all paragraph marks and replacing all of them with either a
space or nothing. That leaves you with one continuous line of text in a
single paragraph. A continuous line of text in a single paragraph is not
what Clarendon wants.

There are no bonus points for wrong answers Peter. I know that you covet an
MVP award, but you are not doing yourself any favors. You really should try
harder to comply with the goals and objective statement number 2:

Post when and wherever you like, but stay in your range of expertise. Always
be open to the ideas and suggestion of others. If you venture outside your
range then try to be correct.


--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR


Greg,

You have made a literalist assumption that the example put into the
original posting is representative of the entire text.

If the entire text is indeed sets of four lines that are to be
combined into two paragraphs, then your solution will work as well as
mine.

If it isn't, then it won't.

(Since the example text is the same words stated twice, it's unlikely
that it's an actual four-line slice of the original.)
 
C

Clarendon

Dear Greg

Oh, my God! It works! Thank you so~ much. To be honest I didn't expect to be
able to do it this far. This opens a new horizen in my use of the Word. How
long would it take if I were to learn how to program like you? Anyway, thanks
again and I am clicking Yes to all your replies!
 
G

Greg Maxey

Clarendon,

Oh yea of little faith!

Yes there are a lot of doors that open when you decide to learn how to use
each of the many tools in the Office toolbox including the hammer. Here you
and I have learned to use it to meet your needs while Mr. Daniels has sat
beating himself over the head with it ;-)

I can't speak for others, but for me VBA is a continuous learning process.
I have been tinkering with it (tinkering with it a lot) for about 6 years.
There are many features of VBA that are still dark mysteries, but the fun
part is that you can start learning something almost instantly and then go
as far as your interest takes you. I can't personally endorse a good book
on the subject, because I have never read one. However, my friend Jonathan
West suggests that if you only buy one book on programming buy Code Complete
by Steve McConnell. You can also get a start at these links.

http://word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm

http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm

http://word.mvps.org/FAQs/MacrosVBA/index.htm

Thank you for your offer to check "yes" to my replies, however I am not the
aspiring Word MVP. It will do the Word community a better service to ensure
you check "no" to all of Mr. Daniel's.

Good luck.
--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
 
G

Greg Maxey

Peter,

You've been shown that you are wrong again. It will probably be slow in the
newsgroup today so I suggest you could spend some time reflecting on your
goal and objective statement 3, 4, and 6.

3. Stop posting your opinions as statements of fact. If you think something
is easy or if you prefer one method to another then say so in that manner.
Stop insisting or trying to prove that your ways are always best, easiest,
fastest, etc. Let others decided for themselves what is easiest between a
set of given options and decide for themselves if the effort/advantage of
pursuing one approach justifies taking that approach over another.

4. Stop disparaging the contributions and skills of others and selective
advanced Word features. Stop throwing up roadblocks and detours when a user
seeks information on a particular feature or function that you don't
understand or that you don't wish to pursue yourself.

6. Bridle your arrogance.



Cheers,


--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR


Greg,

You have made a literalist assumption that the example put into the
original posting is representative of the entire text.

If the entire text is indeed sets of four lines that are to be
combined into two paragraphs, then your solution will work as well as
mine.

If it isn't, then it won't.

(Since the example text is the same words stated twice, it's unlikely
that it's an actual four-line slice of the original.)
 
P

Peter T. Daniels

How many of your own ships did you sink during your 30-year Navy
career? Since you can't read simple English, probably quite a few.

If you want paragraphs in your result text, you first replace ^p^p
with ^l (or something similar), then replace ^p with space or nothing,
then replace ^l with ^p.

And I have used the procedure many, many times.

NVP is an "award"?? Since you're so obsessed with me and it, why did
you choose to renounce yours?

Peter,

Why do you post here?  If it is to help other people then please stop as you
only hinder and confuse whenevever you venture out of you very limited,
specialized area of expertise.

I did not assume anything.  I read the man's question and then provideda
solution that addressed his stated need.  Maybe Clarendon's "That's exactly
what I need done" has convinced you. Unless of course you intend to start
arguing with him about what he wants done.

Have you even tried your ridiculous suggestion?  The only thing is doesis
make one long paragraph out of all the paragraphs in the document.  If you
refuse to test it and see for yourself then at least think about it.  You
are finding all paragraph marks and replacing all of them with either a
space or nothing.  That leaves you with one continuous line of text in a
single paragraph.  A continuous line of text in a single paragraph is not
what Clarendon wants.

There are no bonus points for wrong answers Peter.  I know that you covet an
MVP award, but you are not doing yourself any favors.  You really should try
harder to comply with the goals and objective statement number 2:

Post when and wherever you like, but stay in your range of expertise. Always
be open to the ideas and suggestion of others.  If you venture outside your
range then try to be correct.

--
Greg Maxey

Greg,

You have made a literalist assumption that the example put into the
original posting is representative of the entire text.

If the entire text is indeed sets of four lines that are to be
combined into two paragraphs, then your solution will work as well as
mine.

If it isn't, then it won't.

(Since the example text is the same words stated twice, it's unlikely
that it's an actual four-line slice of the original.)

What Greg Maxey is is, how he uses a hammer, or his obsesions are not the
issue here. The issue is once again you have posted gibberish and it is
not
a solution to the problem described.
The problem that Clarendon decribed is he has thousands of paragraph pairs
that he wants to combine into single paragraphs.:


One Two
Three Four
He does not want to create one big giant paragraph as your first
suggestion
would do.
One two three four.
Nor does he want to spend the rest of his life manually adapting his
document.
 
C

Clarendon

Dear Greg

Oh, my God! It works, and thank you so~ much. I didn't really expect I could
go this far. This code will be very very useful for me, and it opens up a new
horizon in my use of Word. How long would it take if I were to learn to be
able to program this like you? Anyway, I am clicking yes! to all your
replies.
 
G

Greg Maxey

Peter,

Hurling insults will not endear you with your fans (plural because there are
two) in the MVP program.

So where are we. Clarendon's issue is completely resolved but let's
entertain you and give his problem a go using your suggested course of
action.

We have the following example text (representative of the entire documnent).

Heading 1 text
A text
A text
B text
B text
Heading 2
C text
C text
D text
D text

Each line is separated by a paragraph mark. Are you with me so far? I'll
wait if you need to catch up.

The desired result is:

Heading 1 text
A textA text
B textB text
Heading 2
C textC text
D textD text

Regardless of how you may feel about the desired result Peter, it is what
the OP wants.

1. First you would find ^p^p and replace with ^l (or something similiar).
Lets use ^l so we stick rigidly to your prescribed course.

2. We click "Replace All."

Word returns "Word has completed the search and made 0 replacements."
So far no harm no foul and we have only wasted a step.

3. Next we find ^p and replace with a space or nothing. Since Clarendon
indicated nothing we will use nothing.

Word returns: "Word has completed the search and has made 10 replacements.
The resulting text is: Heading 1 textA textA textB textB textHeading 2C
textC textD textD text


Oh, dear. It looks like your course is heading you towards shoal water!



4. Finally, and I realize that is is a further waste of time, just to be
complete. We find ^l and replace with ^p.



It comes as no surprise that Word returns: "Word has completed the search
and made 0 replacements."

The final result after completed all of your prescribed steps is: Heading 1
textA textA textB textB textHeading 2C textC textD textD text.



Peter your ship, if not sunk, is firmly stuck agound ;-). Unfortunately of
no real consequence here. It is a grave offense when dealing with real
ships. You would have torpedoed your Word career and MVP aspirations and you
wouldn't get another chance.



Your suggestion and method may often be a solution to your particular
problem. Unfortunately it isn't a solution to Clarendon's problem and you
don't get a gold star this time. Sorry Peter.



Why did I disassociate from the MVP program? Isn't it obvious? To make a
spot for you :)



Cheers.



How many of your own ships did you sink during your 30-year Navy
career? Since you can't read simple English, probably quite a few.

If you want paragraphs in your result text, you first replace ^p^p
with ^l (or something similar), then replace ^p with space or nothing,
then replace ^l with ^p.

And I have used the procedure many, many times.

NVP is an "award"?? Since you're so obsessed with me and it, why did
you choose to renounce yours?

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR
 
P

Peter T. Daniels

Once again, you failed to read my instructions. The part that began
with the capitalized word

HOWEVER.

If you'll read that caveat, you'll find that you've just wasted an
awful lot of typing.

The ONLY reason I'm wasting typing by replying to you is in case
someone comes across your message and tries applying your perversion
of my method for solving the problem of cleaning up line-paragraphed
text _where all the paragraphed lines do NOT come in groups of exactly
two_. (Or whatever your kludge ended up fixing.)
 
S

Suzanne S. Barnhill

While that method is quite successful for many cases where text cleanup is
required, it does not address the OP's problem, which Greg's macro, like it
or not, did. The replace method is described in my article at
http://sbarnhill.mvps.org/WordFAQs/CleanWebText.htm, and Greg offers a macro
solution for similar situations at
http://gregmaxey.mvps.org/Clean_Up_Text.htm.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

Once again, you failed to read my instructions. The part that began
with the capitalized word

HOWEVER.

If you'll read that caveat, you'll find that you've just wasted an
awful lot of typing.

The ONLY reason I'm wasting typing by replying to you is in case
someone comes across your message and tries applying your perversion
of my method for solving the problem of cleaning up line-paragraphed
text _where all the paragraphed lines do NOT come in groups of exactly
two_. (Or whatever your kludge ended up fixing.)
 
G

Greg Maxey

Peter,

You can continue thrashing all you want. I don't care. Ms. Barnhill
has thrown you a lifeline. Perhaps you should grab hold and try to
make it back to shore. Your ship is sunk and you are in over your
head.

Your proposed solution might work for some problems that you have, but
it doesn't work for the OPs problem. Do you really think that he
wanted to go through and manually add thousands of paragraphs just so
he could make your solution work and make you happy?

Try to stay within your range.

Cheers,

Greg
 

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