这个 Word VBA 宏将计算选择中的单词数。 如果没有选择,它将计算整个文档中的单词数。This Word VBA Macro will count the number of words in the selection. If no selection is made, it will count the number of words in the entire document. Sub mynzWordCount() '计算整个文档,然后计算选择的字数(如果选择了某些内容) Dim nWordsCount As Long Dim nCharCount As Long nWordsCount = ActiveDocument.Range.ComputeStatistics(wdStatisticWords) nCharCount = ActiveDocument.Range.ComputeStatistics(wdStatisticCharacters) MsgBox "整个文档包含: " & vbCrLf & nWordsCount & " 单词和" & vbCrLf & _ nCharCount & " 没有空格的字符", , "Word Count" '现在显示所选文本的字数 If Selection.Words.Count >= 1 And Selection.Type <> wdSelectionIP Then nWordsCount = Selection.Range.ComputeStatistics(wdStatisticWords) nCharCount = Selection.Range.ComputeStatistics(wdStatisticCharacters) MsgBox "所选文本包含: " & vbCrLf & nWordsCount & " 单词和" & vbCrLf & _ nCharCount & " 没有空格的字符", , "Word Count (selection)" End IfEnd Sub 【分享成果,随喜正能量】我20多年的VBA实践经验,全部浓缩在下面的各个教程中: 【分享成果,随喜正能量】一个选择便是一种人生,一杯清茶便是一种解读,一个态度便是一种潇洒,一份胸襟便是一种豪迈,一份选择便是一份热爱,一份选择便成长长一生。早安。。