1.在【工具】---->【宏】----->【Visual Basic编辑器】

2.在跳出的窗口敲入下面的代码:
Sub FindText()
Text = InputBox("请输入您要统计的文字", "查找")
With ActiveDocument.Content.Find
Do While .Execute(FindText:=Text) = True
total = total + 1
Loop
End With
MsgBox ("There are totally " + Str(total) + " " + Text + " in this document."), 48, "Finish"
End Sub
Text = InputBox("请输入您要统计的文字", "查找")
With ActiveDocument.Content.Find
Do While .Execute(FindText:=Text) = True
total = total + 1
Loop
End With
MsgBox ("There are totally " + Str(total) + " " + Text + " in this document."), 48, "Finish"
End Sub
如图:

3.点击上方的运行键,这时会弹出一个窗口要求你输入要查找的文字

4.输入文字后,点击确定,可得到统计结果

转载于:https://blog.51cto.com/network0546/154879