L
Lara
I use this Count Occurrences public sub with modifications
in several VBA macros I've written (see below). For some
reason, locks up sometimes--here's the pattern, hoping
someone might be able to help--if I run the macro
consisting solely of this count occurrances loop (below),
it runs fine as many times as I care to run it, in
different documents, etc. BUT if I run one of my longer
macros containing it, then I have to close Word and reopen
it or it locks up if I try to run any macro (including the
basic one, below) containing the loop. Is there
some "interaction" I'm missing here or is this
random "Word bad karma" or what? Something that would
make this screwy if run after/before it? Any idea of a
fix/work-around much appreciated!
It locks up (tested by having it print msgboxes with each
step as it loops) after it counts the last occurrance in
the document, after it exits the loop and on the end with
line (it prints a msgbox after the loop line the final
time for the count, but then locks up.
Public Sub CountOccurrences()
'modified by Lara
Dim strSearch As String
strSearch = "<trid:"
icount = 0
With ActiveDocument.Content.Find
.Text = strSearch
.Format = False
.Wrap = wdFindStop
Do While .Execute
icount = icount + 1
Loop
End With
MsgBox Chr$(34) & strSearch & Chr$(34) & " was found " & _
icount & " times."
End Sub
in several VBA macros I've written (see below). For some
reason, locks up sometimes--here's the pattern, hoping
someone might be able to help--if I run the macro
consisting solely of this count occurrances loop (below),
it runs fine as many times as I care to run it, in
different documents, etc. BUT if I run one of my longer
macros containing it, then I have to close Word and reopen
it or it locks up if I try to run any macro (including the
basic one, below) containing the loop. Is there
some "interaction" I'm missing here or is this
random "Word bad karma" or what? Something that would
make this screwy if run after/before it? Any idea of a
fix/work-around much appreciated!
It locks up (tested by having it print msgboxes with each
step as it loops) after it counts the last occurrance in
the document, after it exits the loop and on the end with
line (it prints a msgbox after the loop line the final
time for the count, but then locks up.
Public Sub CountOccurrences()
'modified by Lara
Dim strSearch As String
strSearch = "<trid:"
icount = 0
With ActiveDocument.Content.Find
.Text = strSearch
.Format = False
.Wrap = wdFindStop
Do While .Execute
icount = icount + 1
Loop
End With
MsgBox Chr$(34) & strSearch & Chr$(34) & " was found " & _
icount & " times."
End Sub