didijaba
Well-known Member
- Joined
- Nov 26, 2006
- Messages
- 511
HEllo, I am trying to place number of word count before searched word, for example I search word apple, and there are 3 words apple in text. Result in text should be 1apple, 2apple, 3apple.
this is what I have so far
this is what I have so far
Code:
Sub FindWords()
Dim sResponse As String
Dim iCount As Integer
' Input different words until the user clicks cancel
Do
' Identify the word to count
sResponse = InputBox( _
Prompt:="What word do you want to count?", _
Title:="Count Words", Default:="")
If sResponse > "" Then
' Set the counter to zero for each loop
iCount = 0
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Text = sResponse
' Loop until Word can no longer
' find the search string and
' count each instance
.Replacement.Text = iCount & sResponse 'I HAVE TRIED THIS IT DOES NOT WORK
Do While .Execute
iCount = iCount + 1
Selection.MoveRight
Loop
End With
' show the number of occurences
MsgBox sResponse & " appears " & iCount & " times"
End With
Application.ScreenUpdating = True
End If
Loop While sResponse <> ""
End Sub