Stripping Hard Returns

J

Joan NYC

Thanks Russ

I will hold on to this

However, the other one seems perfect

I'll have to test it out of the docs I have at work

Russ said:
Joan,
Here is what I suggested, also, to work with a **selection**, in case
Jonathan's routine doesn't satisfy your requirements. This routine is less
likely to make all the previous 'non-Word paragraphs' into one big 'non-Word
paragraph', if you select over multiple 'non-Word paragraphs'.
(Mac users need to substitute \n for ^13)

Sub StripMultipleReturns2()

With Selection.Find
.Text = "^13{3,}"
.Replacement.Text = "^p^p"
.MatchWildcards = True
.Format = False
.Wrap = wdFindStop
.Execute replace:=wdReplaceAll
End With

End Sub

After using above sub use this one to make the 'non-Word paragraphs' more
like Word paragraphs:
Sub PutSoftReturnsInParagraphs()

With Selection.Find
.Text = "[!^13]^13[!^13]"
.Replacement.Text = "^l"
.MatchWildcards = True
.Format = False
.Wrap = wdFindStop
.Execute replace:=wdReplaceAll
End With

End Sub

Then to reduce consecutive paragraph marks:
Sub EliminateContiguousParagraphMarks()

With Selection.Find
.Text = "^13{2,}"
.Replacement.Text = "^p"
.MatchWildcards = True
.Format = False
.Wrap = wdFindStop
.Execute replace:=wdReplaceAll
End With

End Sub

Thank you. Thank you. Thank you!!!

This is EXACTLY what I was looking for

Now I have to bring it to work tomorrow. It will save me tons of time and
wrist action!

I also want to thank everyone else for their input
 
J

Joan NYC

Took this macro to work today and it worked beautifully on very long document

However, I just selected a portion of a different doc (maybe 1 page) and got
Run-Time '5692'

The debugger had ".Execute replace:=wdReplaceAll" highlighted

Thought you would be interested to know this AND was wondering what I did
this time that made it not work when it worked perfectly before

Thanks
 
R

Russ

Joan,
If you're using Jonathan's macro, try replacing his .Text line:
..Text = "^p^p"
with
..Text = "^13^13"
Because the first line will give an error if matchwildcards is selected in
the find dialog or add .MatchWildcards = False to his code.
 
R

Russ

Oops, I should be more clear.
With .Text = "^p^p" use .MatchWildcards = False
And
With .Text = "^13^13" use .MatchWildcards = True
 
J

Joan NYC

Thanks Russ

Interestingly enough when I tried it on a different doc later in the day it
worked fine again... more than once

Possibly something with the way I made the selection on thedoc I had the
problem with

I will hold on to your solution, however

Thanks
 
R

Russ

Joan,
What I meant to offer was what I thought would be a 'permanent' fix to the
5692 error code. Usually when you manually check or use code to check the
checkbox in the Find and Replace dialog to use wildcards in your search that
checkbox option becomes 'sticky' and the next time you open the dialog box,
it will still be checked.
If it is checked while running a subroutine that needs that option to be
False, and if you don't explicitly make it False in code, then you might get
that error code. It might appear to be a 'random' event, if you didn't know
that some of the dialog options are 'sticky'.
So go ahead and add the line to Jonathan's code, it won't change its intent,
but it might stop the 'random' error.
..Text = "^p^p"
..MatchWildcards = False
 
J

Joan NYC

Thanks Russ

I will do this

I probably did have the Find/Replace Wildcard option checked as I use it
quite often

However, I will add your code

This macro has served me so much time and tedium

Thanks to all
 
J

Jean-Guy Marcil

Jonathan West was telling us:
Jonathan West nous racontait que :
Hi Joan

This macro should do nicely for you. Select some text you want
multiple returns strippeed out of, and run this macro

Sub StripMultipleReturns

Dim iEnd as Long

With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p"
.Format = False
.Wrap = wdFindStop
Do
iEnd = Selection.End
.Execute Replace:=wdReplaceAll
Loop While Selection.End < iEnd
End With

End Sub

Just curious Jonathan,

I suggested right off the bat that she uses:

<quote>
Make sure you check the Wildcard options (Click on the "More" button at the
bottom of the Replace dialog).

Then, in the "Find what:" field, type:
(^13)@
and in the "Replace with" field:
^13
and hit "Replace All"

<\quote>

And you suggested the same thing, but through a macro.

She replied that my method did not work, and now she says that yours did?

Why is that?

What is actually different?





--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

Just curious Jonathan,

I suggested right off the bat that she uses:

<quote>
Make sure you check the Wildcard options (Click on the "More" button at
the
bottom of the Replace dialog).

Then, in the "Find what:" field, type:
(^13)@
and in the "Replace with" field:
^13
and hit "Replace All"

<\quote>

And you suggested the same thing, but through a macro.

She replied that my method did not work, and now she says that yours did?

Why is that?

What is actually different?


Hi Jean-Guy,

I've always tended to avoid using wildcards in searches, I'm not
sufficiently certain that they will do what I intend them to do.

I just tried your version out on a test document and found that one
unexpected and unwelcome side effect was that all paragraphs formatted using
in a style other than Normal got reset to Normal style. On my version, style
formatting was maintained.
 
J

Jean-Guy Marcil

Jonathan West was telling us:
Jonathan West nous racontait que :
Hi Jean-Guy,

I've always tended to avoid using wildcards in searches, I'm not
sufficiently certain that they will do what I intend them to do.

Never really had any problem with them, but I know what you mean!
I just tried your version out on a test document and found that one
unexpected and unwelcome side effect was that all paragraphs
formatted using in a style other than Normal got reset to Normal
style. On my version, style formatting was maintained.

True about the formatting, but the answer the OP gave was that it did not
work. I was kind of surprised, but I am relieved to see that it does work.

As for the formatting, I had assumed that her document was all in Normal
style to start with (She did say that a very inexperienced user created the
document).

But, if you want to retain formatting use
\1
instead of
^13
in the Replace with field.

Thanks.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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