bad karma with loop?

From: Lara (lava_at_mindspring.com)
Date: 04/08/04


Date: Wed, 7 Apr 2004 19:35:08 -0700

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



Relevant Pages

  • Re: bad karma with loop?
    ... occurrences there are of a particular word in a document ". ... > in several VBA macros I've written. ... > it or it locks up if I try to run any macro (including the ... > basic one, below) containing the loop. ...
    (microsoft.public.word.vba.general)
  • Re: Is a new CL standard possible?
    ... standardize iterate (with iterate, ... LOOP is standard. ... everything you can do with hygienic macros you can ...
    (comp.lang.lisp)
  • Re: Is a new CL standard possible?
    ... standardize iterate (with iterate, ... No, no, LOOP sucks. ... do with regular macros. ... When I said hygienic macros, ...
    (comp.lang.lisp)
  • Re: [PATCH 2/2] page table iterators
    ... Hugh Dickins wrote: ... but I do like to see what a loop is up to. ... the implementation of the macros is not insanely difficult ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: 2.6.16-rc6-rt1
    ... includes releasing _all_ locks at each ... Or a higher priority task change the structures along the way... ... The basic loop is: ...
    (Linux-Kernel)