replace paragraph marks

H

HGood

Hi, I know how to use Replace to remove paragraph markers at the end of each
line. But I have many pages of text like this below. Every line has a
paragraph marker at the end of it, including the number line.

I want to remove the paragraph markers ONLY from the lines with text, not
the line with a number. So I probably need some code to do this. Is there
some simple code that would accomplish this? Thanks, Harold

1
Tub muaj coob leej yooj xeeb sau
tej xwm txheej kws muaj tshwm
lug tav taag rua huv peb lawm,
2
lawv
le cov tuabneeg kws qhov muag pum
txwj thaus chiv lub keeb lug hab yog
cov kws qha txuj xuv zoo tau muab
cob rua peb lawm.
3
Kuv tub ua tuab
zoo tshawb nrhav txhua yaam nuav
txwj thaus chiv lub keeb lug lawm,
kuv txhad pum zoo muab sau ua ib
qeb zuj zug qha rua koj The-au_la
kws saib hlub,
4
sub koj txhad paub
qhov tseeb txug zaaj nuav kws tub
txeev muaj tuabneeg qha rua koj
paub lawd.
Qha txug yuav yug Yauhaa
5
 
D

Doug Robbins - Word MVP

Use a Wildcard Replace to replace [0-9]{1,}^13 with ###; then use an
ordinary Replace to remove the paragraph marks from the ends of the lines of
text, and then another ordinary Replace to replace the ### with ^p to
reinstate the paragraph marks after the numbers.

Are you sure however that you want to replace the paragraph mark at the end
of the text immediately before a number.

If not, in place of the above Wildcard Replace, use ^13([0-9]{1,})^13 and
replace it with ###\1###

For an explanation, see the article "Finding and replacing characters using
wildcards" at:

http://www.word.mvps.org/FAQs/General/UsingWildcards.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
H

Helmut Weber

Hi HGood,

nothing wrong with Doug's suggestions for sure,
and, if you've followed his advice,
the task would have been completed
long before the code was put together.

OK, there was no other amusement: :)

Sub Macro7()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
If Not (oPrg.Next Is Nothing) Then
If Not IsNumeric(oPrg.Range.Text) And _
Not IsNumeric(oPrg.Next.Range.Text) Then
oPrg.Range.Characters.Last = " "
End If
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

HGood

Thanks very much, I'm traveling right now but I look forward to trying this.
I hadn't thought of wildcards.

Harold

Doug Robbins - Word MVP said:
Use a Wildcard Replace to replace [0-9]{1,}^13 with ###; then use an
ordinary Replace to remove the paragraph marks from the ends of the lines of
text, and then another ordinary Replace to replace the ### with ^p to
reinstate the paragraph marks after the numbers.

Are you sure however that you want to replace the paragraph mark at the end
of the text immediately before a number.

If not, in place of the above Wildcard Replace, use ^13([0-9]{1,})^13 and
replace it with ###\1###

For an explanation, see the article "Finding and replacing characters using
wildcards" at:

http://www.word.mvps.org/FAQs/General/UsingWildcards.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

HGood said:
Hi, I know how to use Replace to remove paragraph markers at the end of
each
line. But I have many pages of text like this below. Every line has a
paragraph marker at the end of it, including the number line.

I want to remove the paragraph markers ONLY from the lines with text, not
the line with a number. So I probably need some code to do this. Is there
some simple code that would accomplish this? Thanks, Harold

1
Tub muaj coob leej yooj xeeb sau
tej xwm txheej kws muaj tshwm
lug tav taag rua huv peb lawm,
2
lawv
le cov tuabneeg kws qhov muag pum
txwj thaus chiv lub keeb lug hab yog
cov kws qha txuj xuv zoo tau muab
cob rua peb lawm.
3
Kuv tub ua tuab
zoo tshawb nrhav txhua yaam nuav
txwj thaus chiv lub keeb lug lawm,
kuv txhad pum zoo muab sau ua ib
qeb zuj zug qha rua koj The-au_la
kws saib hlub,
4
sub koj txhad paub
qhov tseeb txug zaaj nuav kws tub
txeev muaj tuabneeg qha rua koj
paub lawd.
Qha txug yuav yug Yauhaa
5
 
Top