很多大学对学生的论文作品有字数要求,并且字数统计不包含论文里的表格。
遗憾的是,Word软件本身的字数统计没有去除表格字数的功能,所以需要特别的方法搞定这个需求。
方法如下:
[loginview]
原理:使用Word自带的Macro宏命令编辑器,添加一段可统计字数的代码,然后运行新添加的这个宏命令。
在最新版本的Word软件里,点击View,点击最右侧Macro,调出Macro宏管理界面,点击+,打开Macro编辑器,Normal – Insert – Module, 添加自定义宏命令,实现上述功能。
粘贴以下代码保存:
代码版本一(微软工程师MVP提供)
Sub TableWordCount()
Dim Tbl As Table, d As Long, t As Long
With ActiveDocument
For Each Tbl In .Tables
With Tbl
t = t + .Range.ComputeStatistics(wdStatisticWords)
End With
Next
d = .Range.ComputeStatistics(wdStatisticWords)
End With
MsgBox “There are:” & vbCr & _
d & ” words in the document body, including” & vbCr & _
t & ” words in tables.” & vbCr & vbCr & “There are” & vbCr & _
d – t & ” words in the document body, excluding tables.”
End Sub
代码版本二(网络来源)
Sub ExcludeTableAndCaptionWordsFromWordCount() Dim objTable As Table Dim objParagraph As Paragraph Dim objDoc As Document Dim nTableWords As Integer, nDocWords As Integer, nWordCount As Integer, nCaptionWords As Integer Set objDoc = ActiveDocument nTableWords = 0 nCaptionWords = 0 nDocWords = ActiveDocument.ComputeStatistics(wdStatisticWords) With objDoc For Each objTable In .Tables nTableWords = nTableWords + objTable.Range.ComputeStatistics(wdStatisticWords) Next objTable End With With objDoc For Each objParagraph In .Paragraphs If objParagraph.Range.Style = "Caption" Then nCaptionWords = nCaptionWords + objParagraph.Range.ComputeStatistics(wdStatisticWords) End If Next objParagraph End With nWordCount = nDocWords - nTableWords - nCaptionWords MsgBox ("There are " & nWordCount & " main text words in this document." & vbCr & "The following items are excluded from word count: " & vbCr & "Total words in tables: " & nTableWords & vbCr & "Total caption words: " & nCaptionWords) End Sub
添加完成后,再点击View-Macro,最底部就有你添加的新命令了,点击运行即可。
[/loginview]
希望对你有帮助!