Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Insert pagebreak but ignore the first

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steved - 05 Mar 2008 20:53 GMT
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
fumei - 05 Mar 2008 21:04 GMT
use a counter

I would also suggest NOT using Selection.

>Hello from Steved
>
[quoted text clipped - 26 lines]
>      Loop While Selection.Find.Found
>   End Sub
Steved - 05 Mar 2008 21:34 GMT
Hello Fumei from Steved

Fumei sometimes I might have several occurences, so using a counter is
counter productive.

You have said :I would also suggest NOT using Selection." Would you kindly
explain what you would do instead please.

Thankyou.

> use a counter
>
[quoted text clipped - 30 lines]
> >      Loop While Selection.Find.Found
> >   End Sub
Tony Jollans - 05 Mar 2008 22:52 GMT
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

Signature

Enjoy,
Tony

> Hello from Steved
>
[quoted text clipped - 27 lines]
>      Loop While Selection.Find.Found
>   End Sub
Steved - 06 Mar 2008 00:27 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.