-----Original Message-----
Yes. Keep the function as is. Add the follwoing Sub to
the module:
Sub CountStringInDoc()
Dim findthis, messg As String, thenum As Long
findthis = InputBox("Enter the word or phrase to
count.", "Count in Document")
thenum = CountInDoc(ActiveDocument, findthis)
If thenum = 1 Then messg = " time in this document."
Else messg = " times in this document."
messg = "'" & findthis & "' occurs " & thenum & messg
MsgBox messg, , "Count in Document"
End Sub
As you use this keep in mind that
the .MatchWholeWord, .MatchCase, etc. properties as set
in the original function will affect the results. If you
want to be able to specify those properties at run-time,
you'll need to design your own userform. That would be a
good learning project, by the way.
-----Original Message-----
Could this be set up so that the user can enter what word
(or words) they want to count? For example, if I wanted
to count how many times "United States of America" was
used in a document, could something pop up on the screen
for me to enter the text I want to search for, then count
and return the number of occurrences?
Thanks again!
-----Original Message-----
Function CountInDoc(ByVal d As Document, findstring As
String) As Long
Set rg = d.Range
With rg.Find
.Text = findstring
.Wrap = wdFindStop
'[Other find settings, such as whole words only,
wrap, match case, etc.]
.Execute
End With
While rg.Find.Found = True
myCount = myCount + 1
rg.Start = rg.End
rg.End = ActiveDocument.Range.End
rg.Find.Execute
Wend
CountInDoc = myCount
End Function
-----Original Message-----
I am using Word XP and would like to create a macro that
counts how many times a word (or a series of words) is
used in the document and return that value.
Help?!!!!
.
.
.
.