G
Greg
Everytime I think that I am beginning to grasp the Find.Execute process
something comes up to cloud my understanding.
Take this small test as an example.
Document text:
Abc abc abc abc
The code:
Public Sub Test()
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.ClearFormatting
.Text = "abc"
.Format = False
.Forward = True
.Wrap = wdFindStop
.MatchCase = False
Do While .Execute
myRange.Font.Bold = False
'myRange.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub
I understand that I could use a replace:=wdReplaceAll operation here
but I am trying to get my head around stepping through each found term
and performing an action.
Most of the time when I try something like this I can spend 15 minutes
or more trying stop circular loops. After a while it dawns on me to
put in the wdFindStop line and the Collapse Direction line.
What I don't understand is why a loop is not occurring when I run the
code above with the .collapse line activated?
something comes up to cloud my understanding.
Take this small test as an example.
Document text:
Abc abc abc abc
The code:
Public Sub Test()
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.ClearFormatting
.Text = "abc"
.Format = False
.Forward = True
.Wrap = wdFindStop
.MatchCase = False
Do While .Execute
myRange.Font.Bold = False
'myRange.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub
I understand that I could use a replace:=wdReplaceAll operation here
but I am trying to get my head around stepping through each found term
and performing an action.
Most of the time when I try something like this I can spend 15 minutes
or more trying stop circular loops. After a while it dawns on me to
put in the wdFindStop line and the Collapse Direction line.
What I don't understand is why a loop is not occurring when I run the
code above with the .collapse line activated?