vba 统计Word 字数、页数等信息

vba 统计Word 字数、页数等信息
vba 统计Word 字数、页数等信息

VBA 统计Word 字数、页数等信息

方法一. 使用Document.BuiltInDocumentProperties 方法统计

适用于Document对象和Template 对象。返回一个DocumentProperties 集合,该集合代表了指定文档的所有内置的文档属性。

可使用的参数有:

wdPropertyAppName 应用程序名.

wdPropertyAuthor 作者.

wdPropertyBytes 字节数.

wdPropertyCategory 类别.

wdPropertyCharacters 字符数.

wdPropertyCharsWSpaces 字符数(计空格).

wdPropertyComments 批注.

wdPropertyCompany 公司.

wdPropertyKeywords 关键词.

wdPropertyLastAuthor 上一个作者.

wdPropertyLines 行数.

wdPropertyManager 经理.

wdPropertyNotes 注释.

wdPropertyPages 页数.

wdPropertyParas 段数.

wdPropertyRevision 修订次数.

wdPropertySecurity 安全性.

wdPropertySubject 主题.

wdPropertyTemplate 模板.

wdPropertyTimeCreated 创建时间.

wdPropertyTimeLastPrinted 上次打印时间.

wdPropertyTimeLastSaved 上次保存时间.

wdPropertyTitle 标题.

wdPropertyVBATotalEdit 编辑时间总计.

wdPropertyWords 字数.

如要统计一篇活动word文档的字数:ActiveDocument.BuiltInDocumentProp erties(wdPropert yWords)

方法二.使用https://www.360docs.net/doc/f315841475.html,puteStatistics方法统计

可使用的参数如下:

wdStatisticCharacters 字符数.

wdStatisticCharactersWithSpaces 字符数(计空格).

wdStatisticFarEastCharacters 中文字符和朝鲜文.

wdStatisticLines 行数.

wdStatisticPages 页数.

wdStatisticParagraphs 段数.

wdStatisticWords 字数.

使用如下:

统计活动文档的字数(包括脚注):

1.应用于Document 对象的ComputeStatistics 方法。

https://www.360docs.net/doc/f315841475.html,puteStatistics(Statistic:=wdStat isticWords, _ IncludeFoo tnotesAndEndnotes:=True)

2.应用于Range 对象的ComputeStatistics 方法。

https://www.360docs.net/doc/f315841475.html,puteStatistics(Statistic:=wdStatisticWor ds, _ IncludeFootnotesAn dEndnotes:=True)

例:显示Report.doc 第一段中的字数和字符数。

Set myRange = Documents("Report.doc").Paragraphs(1).Range

wordCount = https://www.360docs.net/doc/f315841475.html,puteStatistics(Statistic:=wdStatisticWo rds)

charCount = https://www.360docs.net/doc/f315841475.html,puteStatistics(Statistic:=wdStatisticCh aracters) MsgBox "The first paragraph contains " & wordCount _ & " words and a total of " & charCount & " characters."

统计活动文档的字数也可以写成

https://www.360docs.net/doc/f315841475.html,puteStatistics(wdStatistic Words)

方法三、利用ActiveWindow.Panes(1).Pages.Count 属性(比较好的方法)

Sub Get_wordpages()

'打开当前目录下面的市场研究实务word文档

Documents.Open Filename:=ThisWorkbook.Path & "\市场研究实务.doc"

'统计页数

MsgBox Documents("市场研究实务.doc").ActiveWindow.Panes(1).Pages.Count

Documents.Close SaveChanges:=False

End Sub

方法四、直接使用Count属性,但这种方法统计不准,可以统计隐藏文本内容。

使用如下:

统计段数ActiveDocument.Paragraphs.Count

统计字数ActiveDocument.Words.Count

方法四. 直接调用word的内建方法Dialogs()

统计中文字数:

Dialogs(wdDialogToolsWordCount).Execute

MsgBox Dialogs(wdDialogToolsWordCount).DBCs 或

MsgBox Dialogs(wdDialogToolsWordCount).SBCs

相关主题
相关文档
最新文档