Group: microsoft.public.word.vba.general
From: "Tony Jollans"
Date: Thursday, March 06, 2008 2:54 AM
Subject: Re: Insert pagebreak but ignore the first

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

--
Enjoy,
Tony

"Steved" wrote in message
news:C2D6DA17-BC61-497E-8EC0-E9C8BAC4A95B@microsoft.com...
> 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
>
>
>
>
>
> "Tony Jollans" wrote:
>
>> 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
>>
>>
>> --
>> Enjoy,
>> Tony
>>
>> "Steved" wrote in message
>> news:63D86BD9-A4EA-47C7-8A39-55D78F6F0D60@microsoft.com...
>> > Hello from Steved
>> >
>> > Please how do I tell the macro to ignore the first instance off the
>> > text
>> > "Race" because I would like the macro to only do the second "Race" and
>> > then
>> > do all the next pageinserting. Thankyou.
>> >
>> > 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
>> >
>>
>>

Safety Articles | Usenet Groups | Usenet News | Bluegrass