Maybe try this:
Sub CountWordOccurrences() Dim WordToFind As String Dim WordCount As Long Dim i As Long Dim FoundRange As Range ' Get the word to find from the user WordToFind = InputBox("Enter the word to find:", "Find Word") ' Exit if the user cancels the input box If WordToFind = "" Then Exit Sub ' Make the word case-insensitive for the search WordToFind = LCase(WordToFind) ' Loop through each word in the document For i = 1 To ActiveDocument.Words.Count ' Check if the current word matches the word to find If LCase(ActiveDocument.Words(i)) = WordToFind Then WordCount = WordCount + 1 End If Next i ' Display the result in a message box MsgBox "The word '" & WordToFind & "' occurs " & WordCount & " times in the document.", vbInformation End If End Sub




Reply With Quote