K
Ken
I am trying to write code that will count the number of times a style
is used in a document.
The following code works some of the time but results in an endless
loop under some circumstances (the i < 1000 eventually exits the loop
if this happens). I have determined that the endless loop will occur
if the found text is within a table cell, is the last paragraph in the
cell and there is no paragraph character at the end of the text. I can
use .Information(wdWithInTable) to detect this and take appropriate
action.
However, there seems to be other circumstances when an endless loop
can occur.
Does anyone have a solution to this problem?
With tRange.Find
.ClearFormatting
.Style = “Normal” ‘ or whatever style is to be found
i = 0
testr = True
Do While testr And i < 1000
testr = .Execute(findtext:="", replacewith:="", MatchCase:=False,
_
Wrap:=wdFindStop, MatchWholeWord:=False, _
Forward:=True, Replace:=wdReplaceNone)
If testr Then i = i + 1
Loop
End With
is used in a document.
The following code works some of the time but results in an endless
loop under some circumstances (the i < 1000 eventually exits the loop
if this happens). I have determined that the endless loop will occur
if the found text is within a table cell, is the last paragraph in the
cell and there is no paragraph character at the end of the text. I can
use .Information(wdWithInTable) to detect this and take appropriate
action.
However, there seems to be other circumstances when an endless loop
can occur.
Does anyone have a solution to this problem?
With tRange.Find
.ClearFormatting
.Style = “Normal” ‘ or whatever style is to be found
i = 0
testr = True
Do While testr And i < 1000
testr = .Execute(findtext:="", replacewith:="", MatchCase:=False,
_
Wrap:=wdFindStop, MatchWholeWord:=False, _
Forward:=True, Replace:=wdReplaceNone)
If testr Then i = i + 1
Loop
End With