Automatically removing Enter key

G

Greg Maxey

Peter,

Yes, I forgot to mention that I did see your HOWEVER. I also overlooked
suggesting that you should also reflect on goals and objectives statement
number 5.

5. STOP SHOUTING in the newsgroup.

I think the only reason you wasted more typing is because like in most other
cases even when wrong you continue with your arguments.

"Your method" up cleaning up text. Please Peter. As Ms. Barnhill has
pointed out, that method is well documented and published on her website and
mine. What she didn't mention was that it has been so published long before
you crawled out from under your rock and joined this newsgroup.

Your beat Luke. Stay down.

--
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


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

This post is intended as my epilogue to this tortured thread in fairness to
Mr. Daniels and anyone else who might one day read it.

The suggestion that Mr. Daniels makes is a relatively common practice when
the objective is to clean up text containing extraneous paragraph marks that
will be present if the author of the text didn't use Words' wrap feature and
instead used the enter key to start each new line. A variation of the
method that is often used for cleaning up text pasted from the web is well
documented here: http://sbarnhill.mvps.org/WordFAQs/CleanWebText.htm

This was not the problem presented by Clarendon in the original post.

In his original post Clarendon clearly indicated that he was dealing with
thousands of paragraph pairs that he need to combine. Manually adding the
thousands of extra paragraphs as required by Mr. Daniel's suggestion did not
make it a particularily appealing solution.

After Clarendon posted again and indicated that his paragraph pairs were
separated by Heading 1 text Mr. Daniel's suggestion was completely
irrevelent.

If you read through all of the associated posts in this thread you will see
that two alternative suggestions were presented and argured as a solution to
the problem presented. One works and the other doesn't. Still, both remain
presented and I want any future reader of this post will know that as far as
I am concerned you are free, like Clarendon, to exericise your good judgment
and choose what works best for you.
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
 
C

Clarendon

Hi, Greg

Thank you very much for the reference. I've got a bit of a problem, though.
I realize I need to change the para mark into a space rather than to nothing.
To achieve this I tried twigging the code you gave me. Taking hints from your
first code, I changed the ".Delete" to "= Chr(32)". It did what I wanted, but
then the file crashed and turned into 'No response'. So I guess I need your
help again. Could you change the code for me so it changes the mark into a
space without crashing? Sorry for your trouble.
 
G

Greg Maxey

Clarendon,

With having your physical document, it is hard to say what is causing the
crash. Testing on a very small document, I am having no troubles with
using:

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 = Chr(32)
Next i
Wend
End With
'Delete dummy trailing header
ActiveDocument.Paragraphs.Last.Range.Delete
ActiveDocument.Paragraphs.Last.Range.Delete
End Sub

When you refer to thousands of paragraphs it could be that a buffer is
overloading or something. You might try posting your specific requirement
along with this code in the Word VBA group and someone may have a better
idea for achieving your goal more efficiently.

You could also try breaking the larger document up into a few smaller
pieces, see if the code runs, then combine the pieces.

Good luck.

Hi, Greg

Thank you very much for the reference. I've got a bit of a problem,
though. I realize I need to change the para mark into a space rather
than to nothing. To achieve this I tried twigging the code you gave
me. Taking hints from your first code, I changed the ".Delete" to "=
Chr(32)". It did what I wanted, but then the file crashed and turned
into 'No response'. So I guess I need your help again. Could you
change the code for me so it changes the mark into a space without
crashing? Sorry for your trouble.

--
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
 
C

Clarendon

So I was right in making that change!
I tried it again this time removing the blank line at the end. That might
have been the cause of the crash. I tried about a thousand lines and it
worked fine. Didn't crash! So thank you very much agani!
 
G

Greg Maxey

Clarendon,

Well after all the solution was just a kluge as Mr. Daniels took pains to
point out. Still I suppose a working kluge is better than spending a few
days manually adding paragraphs just to make his suggestion work.

Questions on any future problems related to Word and a VBA solution are
probably best posted in the Word.vba.general group. A lot of the people who
participate in this group also participate there. Fortunately one of them
doesn't.
So I was right in making that change!
I tried it again this time removing the blank line at the end. That
might have been the cause of the crash. I tried about a thousand
lines and it worked fine. Didn't crash! So thank you very much agani!

--
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
 

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