Groupes de discussion : microsoft.public.word.newusers
De : "Doug Robbins" <drobb...@eisa.net.au>
Date : 1999/12/22
Objet : Re: Word Frequency--Can it be done?
Hi Joe,
Here is a macro that will do it: in one document
' a Macro to occurences of a word and of its wordforms
' Macro created Saturday, July 03, 1999 by Doug Robbins
'
'
Dim Message, Title, Default, MyValue
Message = "Enter the word for which you need the number of occurences" '
Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
Selection.HomeKey Unit:=wdStory
With ActiveDocument.Content.Find
.MatchWholeWord = True
Counter = 0
Do While .Execute(FindText:=MyValue, Forward:=True) = True
Counter = Counter + 1
Loop
End With
With ActiveDocument.Content.Find
.MatchAllWordForms = True
Counter1 = 0
Do While .Execute(FindText:=MyValue, Forward:=True) = True
Counter1 = Counter1 + 1
Loop
End With
MsgBox "The word " + MyValue + " appears" + Str$(Counter) + " times."
MsgBox "Words that match the wordform of " + MyValue + " appear" +
Str$(Counter1) + " times."
With some modifications, and integration with the following commands, you
should be able to get it to handle all of the files in a directory
Public Sub BatchWordCount()
file = Dir("C:\My Documents\*.doc")
While file <> ""
Documents.Open FileName:=file
'Insert modified code here *
ActiveDocument.Close SaveChanges:=wdSaveChanges
file = Dir()
Wend
End Sub