Most of the code you have in the loop does not need repeating. You could
rewrite it something like (pseudocode) ...
with selection.find
' set up the find
end with
do
find.execute
etc.
loop
When you have done this you can see that you can just do a preliminary
execute before the loop ... more pseudocode ...
with selection.find
' set up the find
end with
find.execute
do
find.execute
etc.
loop
Hello Tony from Steved
The below macro does not stop I had to use CTRL Break to stop it it was down
to page 875 I've only got 9 so should have stopped at page 9.
Thankyou.
Sub TestPageBreak()
With Selection.Find
Do
.Text = "Race"
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveDown Unit:=wdLine
Loop
End With
End Sub
> Most of the code you have in the loop does not need repeating. You could
> rewrite it something like (pseudocode) ...
[quoted text clipped - 50 lines]
> > Loop While Selection.Find.Found
> > End Sub
Tony Jollans - 06 Mar 2008 08:54 GMT
> The below macro does not stop
That's because you never tell it to stop.
You started out with this:
Sub TimeShift()
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Race"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
Selection.HomeKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveDown Unit:=wdLine
Selection.MoveDown Unit:=wdLine
End If
Loop While Selection.Find.Found
End Sub
As per my suggestion you should have changed it to this:
Sub TimeShift()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "quick"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Do
Selection.Find.Execute
If Selection.Find.Found Then
Selection.HomeKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
Selection.MoveDown Unit:=wdLine
Selection.MoveDown Unit:=wdLine
End If
Loop While Selection.Find.Found
End Sub
The setup of the find is before the loop - as is an extra
Selection.Find.Execute.
Could you try this and see whether it meets your needs before asking further
questions about different code?

Signature
Enjoy,
Tony
> Hello Tony from Steved
>
[quoted text clipped - 71 lines]
>> > Loop While Selection.Find.Found
>> > End Sub
Steved - 06 Mar 2008 19:08 GMT
Thankyou Tony
Yes it does what is required.
> > The below macro does not stop
>
[quoted text clipped - 136 lines]
> >> > Loop While Selection.Find.Found
> >> > End Sub