A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Automatically removing Enter key



 
 
Thread Tools Display Modes
  #21  
Old September 14th, 2009, 01:19 AM posted to microsoft.public.word.docmanagement
Greg Maxey[_2_]
external usenet poster
 
Posts: 649
Default Automatically removing Enter key

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


"Peter T. Daniels" wrote in message
...
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.)

On Sep 13, 10:14 am, "Greg Maxey"
wrote:
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.





Peter T. Daniels wrote:
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?


On Sep 12, 10:40 pm, "Greg Maxey"
wrote:
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


"Peter T. Daniels" wrote in
...
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.)


On Sep 12, 12:31 pm, "Greg Maxey"


wrote:
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.


Peter T. Daniels wrote:
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.


On Sep 12, 9:03 am, Greg Maxey wrote:
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


On Sep 12, 5:42 am, Clarendon
wrote:


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



  #22  
Old September 14th, 2009, 02:49 AM posted to microsoft.public.word.docmanagement
Greg Maxey[_2_]
external usenet poster
 
Posts: 649
Default Automatically removing Enter key

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

Peter T. Daniels wrote:
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.

On Sep 12, 5:42 am, Clarendon
wrote:
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



  #23  
Old September 14th, 2009, 02:08 PM posted to microsoft.public.word.docmanagement
Clarendon
external usenet poster
 
Posts: 47
Default Automatically removing Enter key

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" wrote:

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/...csIn15Mins.htm

http://word.mvps.org/FAQs/MacrosVBA/...ordedMacro.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


"Clarendon" wrote in message
...
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!


"Greg Maxey" wrote:

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.Delet e
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


"Clarendon" wrote in message
...
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.








"Greg Maxey" wrote:

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



On Sep 12, 5:42 am, Clarendon
wrote:
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.








  #24  
Old September 14th, 2009, 09:21 PM posted to microsoft.public.word.docmanagement
Greg Maxey[_2_]
external usenet poster
 
Posts: 649
Default Automatically removing Enter key

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.


Clarendon wrote:
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" wrote:

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/...csIn15Mins.htm

http://word.mvps.org/FAQs/MacrosVBA/...ordedMacro.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


"Clarendon" wrote in message
...
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!


"Greg Maxey" wrote:

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.Delet e
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


"Clarendon" wrote in message
...
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.








"Greg Maxey" wrote:

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



On Sep 12, 5:42 am, Clarendon
wrote:
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



  #25  
Old September 15th, 2009, 09:23 AM posted to microsoft.public.word.docmanagement
Clarendon
external usenet poster
 
Posts: 47
Default Automatically removing Enter key

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" wrote:

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.


Clarendon wrote:
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" wrote:

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/...csIn15Mins.htm

http://word.mvps.org/FAQs/MacrosVBA/...ordedMacro.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


"Clarendon" wrote in message
...
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!


"Greg Maxey" wrote:

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.Delet e
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


"Clarendon" wrote in message
...
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.








"Greg Maxey" wrote:

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:

  #26  
Old September 15th, 2009, 08:00 PM posted to microsoft.public.word.docmanagement
Greg Maxey[_2_]
external usenet poster
 
Posts: 649
Default Automatically removing Enter key

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.

Clarendon wrote:
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" wrote:

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.


Clarendon wrote:
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" wrote:

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/...csIn15Mins.htm

http://word.mvps.org/FAQs/MacrosVBA/...ordedMacro.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


"Clarendon" wrote in message
...
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!


"Greg Maxey" wrote:

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.Delet e
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


"Clarendon" wrote in
message
...
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.








"Greg Maxey" wrote:

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:


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



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:40 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.