What am I not doing for the macro to execute

S

Steved

Hello from Steved
The Below finds "1:25 Race" goes to the start of the line and inserts a
pagebreak,
Please what is required for it to function.

Sub Pagebreak()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
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 With
End Sub

Thankyou.
 
D

Doug Robbins - Word MVP

To start off with, you are setting Wildcards = False, but are using
wildcards.

This however does what you want:

Dim srange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{1,2}:[0-9]{2}[ ]{1,}Race",
Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=False) = True
Set srange = Selection.Bookmarks("\line").Range
srange.Collapse wdCollapseStart
srange.InsertBreak wdPageBreak
Selection.Collapse wdCollapseEnd
Loop
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
P

Pesach Shelnitz

Hi,

The following macro should do what you want. As in the version that I posted
yesterday, this macro continues the search for the next instance of the
search string from the exact point where the previous search ended. In my
opinion, this is better than cursor movements that are based on assumptions
about the presence of line breaks.

Sub Winner()
Dim foundRange As Range
Dim wildcardsEnabled As Boolean

Selection.HomeKey wdStory
With Selection.Find
' Save status of the Match Wildcards check box
wildcardsEnabled = .MatchWildcards
.ClearFormatting
Do While .Execute(FindText:="[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
Set foundRange = Selection.Range
Selection.HomeKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
foundRange.Select
Selection.Collapse Direction:=wdCollapseEnd
Loop
.MatchWildcards = wildcardsEnabled
.Text = ""
End With
End Sub
 
S

Steved

Hello Doug

I checked everything else but forgot to Check Wildcards

Thankyou.

Doug Robbins - Word MVP said:
To start off with, you are setting Wildcards = False, but are using
wildcards.

This however does what you want:

Dim srange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{1,2}:[0-9]{2}[ ]{1,}Race",
Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=False) = True
Set srange = Selection.Bookmarks("\line").Range
srange.Collapse wdCollapseStart
srange.InsertBreak wdPageBreak
Selection.Collapse wdCollapseEnd
Loop
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Steved said:
Hello from Steved
The Below finds "1:25 Race" goes to the start of the line and inserts a
pagebreak,
Please what is required for it to function.

Sub Pagebreak()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
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 With
End Sub

Thankyou.
 
S

Steved

Hello Pesach

Thankyou

This line "Do While .Execute(FindText:="[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE", _"
has been A great help to me.

Pesach Shelnitz said:
Hi,

The following macro should do what you want. As in the version that I posted
yesterday, this macro continues the search for the next instance of the
search string from the exact point where the previous search ended. In my
opinion, this is better than cursor movements that are based on assumptions
about the presence of line breaks.

Sub Winner()
Dim foundRange As Range
Dim wildcardsEnabled As Boolean

Selection.HomeKey wdStory
With Selection.Find
' Save status of the Match Wildcards check box
wildcardsEnabled = .MatchWildcards
.ClearFormatting
Do While .Execute(FindText:="[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
Set foundRange = Selection.Range
Selection.HomeKey Unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
foundRange.Select
Selection.Collapse Direction:=wdCollapseEnd
Loop
.MatchWildcards = wildcardsEnabled
.Text = ""
End With
End Sub

--
Hope this helps,
Pesach Shelnitz


Steved said:
Hello from Steved
The Below finds "1:25 Race" goes to the start of the line and inserts a
pagebreak,
Please what is required for it to function.

Sub Pagebreak()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,2}:[0-9]{2}[ ^s]{1,}RACE"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
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 With
End Sub

Thankyou.
 

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