Hmm

M

M

That is interesting.
I'll mess with this general idea and see if I can figure
out what it's prob is. If I do, I'll post the code. It
should work just the same even tho I am in VB and your
code is for VBA. The methods, etc are all the same.

Got to love it.
 
D

Doug Robbins - Word MVP

If you are trying to limit the count to the occurrences in a particular
range, you would need to do something like:

Dim Message, Title, Default, MyValue, myrange As Range
Set myrange = ActiveDocument.Paragraphs(1).Range
Message = "Enter the word for which you need the number of occurences" '
Title = "InputBox Demo" ' Set title.
Default = "" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
Counter = 0
Do While .Execute(FindText:=MyValue, Forward:=True, Wrap:=wdFindStop) =
True
If Selection.Start >= myrange.Start And Selection.End <= myrange.End
Then
Counter = Counter + 1
End If
Loop
End With
MsgBox "The word " + MyValue + " appears" + Str$(Counter) + " times."

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top