Created
May 10, 2012 03:07
-
-
Save mrowles/2650773 to your computer and use it in GitHub Desktop.
Microsoft Word: Count occurrence of specific word/s in a document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function CountWordsOccurrence() As Integer | |
Application.ScreenUpdating = False | |
Dim sWords As String | |
Dim iCount As Integer | |
'The word which is being counted | |
sWords = "word" | |
'Reset counter for each new file | |
iCount = 0 | |
'Search the document for each occurence of "word": | |
With Selection | |
.HomeKey Unit:=wdStory | |
With .Find | |
.MatchCase = True | |
.ClearFormatting | |
.Text = sWords | |
Do While .Execute | |
iCount = iCount + 1 | |
Selection.MoveRight | |
Loop | |
End With | |
'Show the number of occurences | |
Debug.Print sWords & " appears " & iCount & " times" | |
End With | |
Application.ScreenUpdating = True | |
CountWord = iCount | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment