dorothychai

只有我这么无聊了。。写论文的时候发现每次想看这个章节的字数统计时,还需要全选然后再看字数统计,太麻烦了。所以想着用宏写个能直接查看选定章节的字数统计。

 

具体方法如下:

建立宏:视图--宏--录制宏--宏名--按钮(方便以后点击查看字数)最好将宏保存在所有文档,这样另外打开一个word也可以使用。

随便录制一下,然后结束录制。再编辑刚才的宏即可。

 1 Sub 字数统计()
 2 \'
 3 \' 字数统计 宏
 4 \'
 5 \'
 6 Dim myrange As Range
 7 Dim wordCount As Long
 8 Dim para As Paragraph
 9 Set para = Selection.Paragraphs(1)
10 wordCount = para.Range.ComputeStatistics(wdStatisticWords)
11 On Error Resume Next
12 Do
13     If para.Next.Range.Style = "标题 1" Then
14         Exit Do
15     End If
16     wordCount = wordCount + para.Next.Range.ComputeStatistics(wdStatisticWords)
17     Set para = para.Next
18 Loop While True
19 
20 MsgBox wordCount
21  
22 End Sub

此处的“标题 1”由自己决定。查看你的章节用的什么样式。

分类:

技术点:

相关文章:

  • 2021-12-25
  • 2021-11-01
  • 2018-11-27
  • 2021-11-28
  • 2021-12-25
  • 2021-11-16
  • 2021-12-22
  • 2021-12-03
猜你喜欢
  • 2021-12-25
  • 2021-10-12
  • 2021-12-25
  • 2021-12-30
  • 2021-12-18
  • 2022-12-23
  • 2021-04-19
相关资源
相似解决方案