It just keeps repeating the macro

S

Steved

Hello from Steved

The below macros goes to the end then goes back to the top off the page
and starts again What have I missed please to have it stop.

Sub Breeding()
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "T("
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection.Find
.Text = "BY"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = ","
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Options.DefaultHighlightColorIndex = wdBlue
Selection.Range.HighlightColorIndex = wdBlue
Selection.Font.Color = -603914241
End If
Loop While Selection.Find.Found
End Sub

Thankyou.
 
H

Helmut Weber

Hi Steved,

you are executing a search,
and you have defined a replacement text,
but you do not replace the found text.

Selection.Find.Execute replace:=wdreplaceall

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Doug Robbins - Word MVP

Tell us exactly what it is that the code is supposed to be doing.

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

Steved

Hello Doug

Find "T(" then on the same line find "BY" turn on the extend to the Comma
then go back one space as to not to highlite the comma
Hightlite the background Blue and the text White.

Steved
 
D

Doug Robbins - Word MVP

Can you copy and paste a sample of the text into a message that you post
back here. It will be much easier to work with that than to try and guess
exactly what it is.

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

Steved

Hello Doug

I'm At work at this time meaning I shall give you the sample when I get home
in about 9 hours from now.

Steved
 
S

Steved

Hello Doug


T( 4 0 1) E( 1 0 0) C( 1 0 1) D( 1 0 0) J( 2 0 1) 1:11.64 3 BY WOODMAN,

The above would be Highlited "BY WOODMAN"

Thankyou Steved
 
D

Doug Robbins - Word MVP

Steved,

To get this right, I would need a bit more extensive sample than that, or
some additonal information.

Does each T( commence on a new line. Is the comma after WOODMAN at the end
of the line of does the text continue after that comma?

If it is the end of the line, does the line terminate in a carriage return
so that the line starting with T( and ending with the comma is a paragraph
by itself?

If it is not at the end of the line, will there be multiple pieces of text
such as this in a paragraph, or will there only be one in any one paragraph?

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

Steved

Hello Doug

Doug Robbins - Word MVP said:
Steved,

To get this right, I would need a bit more extensive sample than that, or
some additonal information.
Does each T( commence on a new line.

08976056754 T(

Is the comma after WOODMAN at the end of the line of does the text
continue after that comma?

Text Continues after the Comma

If it is the end of the line,

No it is not at the end off the line

does the line terminate in a carriage return so that the line starting with
T( and ending with the comma is a paragraph by itself?

Yes all on the same line. Paragraph by it's self.

If it is not at the end of the line, will there be multiple pieces of text
such as this in a paragraph, or will there only be one in any one paragraph?

Only one instance per Paragragh.

So in finishing it has text before T( and text after the comma and only one
occurrence per paragraph. ( one line paragraphs )

Thankyou for taking timeout on my issue.
 
D

Doug Robbins - Word MVP

This should do it:

Dim myrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="T(", Forward:=True, MatchWildcards:=False,
Wrap:=wdFindStop) = True
Set myrange = Selection.Paragraphs(1).Range
myrange.Start = myrange.Start + InStr(myrange, "BY") - 1
myrange.End = myrange.Start + InStr(myrange, ",") - 1
myrange.Shading.BackgroundPatternColor = wdColorBlue
myrange.Font.Color = wdColorWhite
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
 

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