> Hi, I've read some of the loop related posts but still can't figure this out.
> Can you help?
[quoted text clipped - 40 lines]
> How do I add the loop? I need it to search for a page break and then delete
> the junk after it. Thanks much!
Thank you Tony!
I tried it, and it deleted lots of pages. Actually I needed it to find the
page break, go into extend mode, search for a space and then delete what it
selects, which would be the junk at the top of the next page. I don't
understand your code enough to fix it myself...thank you so much!
> Hi Julia,
>
[quoted text clipped - 81 lines]
> > How do I add the loop? I need it to search for a page break and then delete
> > the junk after it. Thanks much!
Tony Jollans - 03 Mar 2005 07:43 GMT
Hi Julia,
I based my code on what your original did. To change it as you ask, add a
line after the Execute ..
Sub BillClean()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^m" 'find page break
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute = True
Selection.Collapse wdCollapseEnd
Selection.MoveEndUntil " "
Selection.Delete
Loop
End Sub
The code is fairly straightforward. After setting up the Find, it loops,
executing the Find, and continuing until that returns False. The loop itself
(now) does three things:
a) Collapses the Selection to skip past the found page break
b) Extends the End of the Selection until (but not including) the next space
c) Deletes what is now selected.
Enjoy,
Tony
> Thank you Tony!
>
> I tried it, and it deleted lots of pages. Actually I needed it to find the
> page break, go into extend mode, search for a space and then delete what it
> selects, which would be the junk at the top of the next page. I don't
> understand your code enough to fix it myself...thank you so much!
Helmut Weber - 03 Mar 2005 16:24 GMT
Hi Julia,
you don't need a loop at all,
if you want to delete spaces after a manual pagebreak,
and the pagebreak, too.
(Somehow I got the impression, you don't want to really delete
the pagebreak.) But anyway:
Sub Test0894()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "^m {1,}" ' US-Version
' .Text = "^m {1;}" ' some other countries
.Replacement.Text = ""
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
ResetSearch
End Sub
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub
In case, there are section breaks,
things might get complicated.
See:
http://word.mvps.org/faqs/General/UsingWildcards.htm
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/