Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    count TIMES a word appears. (2002)

    I would like to see if we can count the number to times a word "water" appears in a document.

  2. #2
    Star Lounger
    Join Date
    Jan 2001
    Location
    U.S. - East Coast
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: count TIMES a word appears. (2002)

    Try the following macro:

    <pre>Function WordCount(ByVal strSearchString As String) As Long

    Dim lngWordCount As Long


    With ActiveDocument.Content.Find

    .ClearFormatting
    .Text = strSearchString
    .Forward = True
    .MatchCase = False
    .MatchWholeWord = True

    Do While .Execute() = True
    lngWordCount = lngWordCount + 1
    Loop

    End With

    WordCount = lngWordCount

    End Function

    </pre>


  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: count TIMES a word appears. (2002)

    I think the Replace All feature usually tells you how many words it replaced, so you could replace water with, say, wine, get the count, and change the wine back to water. Of course, you have to use Undo, or you might actually make irreversible changes to your document...

  4. #4
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: count TIMES a word appears. (2002)

    Why not just replace "water" with "water"?
    The only snag might be where "water" is used in combination with something else, like waterfall, water-shed, "Barry Drinkwater", and so on, so you'll have to click on More and check the "Find whole words only" box.

    But you have to be careful of global search and replace...
    Someone had written a long account of a military event, and had used the word "Major" throughout. Wanting to change the rank, he did a global search and replace of "Major" by "Captain".
    Which was all jolly fine and good, until he saw the story published, wherein it referred to "The Prime Minister, John Captain", to the considerable puzzlement of most readers...!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  5. #5
    Lounger
    Join Date
    Jan 2001
    Location
    Milton Keynes, Buckinghamshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: count TIMES a word appears. (2002)

    Daniel,

    Word 2002 will do this for you very simply. In the find dialogue tick the box in the bottom left corner labelled "Highlight all items found in:". The "Find next" button is re-labelled "Find all". When you click it, Word selects every occurrence of your "Find what:" text, and ungrammatically reports that, "Word found nn items matching this criteria". The initial search is on the Main text of the document, and you need to repeat the Find for footnotes and end notes, comments etc. if these are also to be included.

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: count TIMES a word appears. (2002)

    <hr>Of course, you have to use Undo, or you might actually make irreversible changes to your document... <hr>
    If you replace with ^& (= search text), you don't risk to change anything.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •