方法一. 使用.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.BuiltInDocumentProperties(wdPropertyWords)
方法二.使用ComputeStatistics方法统计
可使用的属性如下:
成员名 描述
wdStatisticCharacters 字符数.
wdStatisticCharactersWithSpaces 字符数(计空格).
wdStatisticFarEastCharacters 中文字符和朝鲜文.
wdStatisticLines 行数.
wdStatisticPages 页数.
wdStatisticParagraphs 段数.
wdStatisticWords 字数 .
使用如下:
统计活动文档的字数(包括脚注):
1.应用于 Document 对象的 ComputeStatistics 方法。
ActiveDocument. ComputeStatistics(Statistic:=wdStatisticWords, _ IncludeFootnotesAndEndnotes:=True)
2.应用于 Range 对象的 ComputeStatistics 方法。
.Range.ComputeStatistics(Statistic:=wdStatisticWords, _ IncludeFootnotesAndEndnotes:=True)
例:显示 Report.doc 第一段中的字数和字符数。
统计活动文档的字数也可以写成
ActiveDocument.Range.ComputeStatistics(wdStatisticWords)
方法三.直接使用Count属性,但这种方法统计不准,可以统计隐藏文本内容。
使用如下:
统计段数 ActiveDocument.Paragraphs.Count
统计字数 ActiveDocument.Words.Count
方法四. 直接调用word的内建方法Dialogs()
统计中文字数:
Dialogs(wdDialogToolsWordCount).Execute
MsgBox Dialogs(wdDialogToolsWordCount). DBCs 或
MsgBox Dialogs(wdDialogToolsWordCount).SBCs
适用于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.BuiltInDocumentProperties(wdPropertyWords)
方法二.使用ComputeStatistics方法统计
可使用的属性如下:
成员名 描述
wdStatisticCharacters 字符数.
wdStatisticCharactersWithSpaces 字符数(计空格).
wdStatisticFarEastCharacters 中文字符和朝鲜文.
wdStatisticLines 行数.
wdStatisticPages 页数.
wdStatisticParagraphs 段数.
wdStatisticWords 字数 .
使用如下:
统计活动文档的字数(包括脚注):
1.应用于 Document 对象的 ComputeStatistics 方法。
ActiveDocument. ComputeStatistics(Statistic:=wdStatisticWords, _ IncludeFootnotesAndEndnotes:=True)
2.应用于 Range 对象的 ComputeStatistics 方法。
.Range.ComputeStatistics(Statistic:=wdStatisticWords, _ IncludeFootnotesAndEndnotes:=True)
例:显示 Report.doc 第一段中的字数和字符数。
Set myRange = Documents("Report.doc").Paragraphs(1).Range wordCount = myRange.ComputeStatistics(Statistic:=wdStatisticWords) charCount = _ myRange.ComputeStatistics(Statistic:=wdStatisticCharacters) MsgBox "The first paragraph contains " & wordCount _ & " words and a total of " & charCount & " characters."
统计活动文档的字数也可以写成
ActiveDocument.Range.ComputeStatistics(wdStatisticWords)
方法三.直接使用Count属性,但这种方法统计不准,可以统计隐藏文本内容。
使用如下:
统计段数 ActiveDocument.Paragraphs.Count
统计字数 ActiveDocument.Words.Count
方法四. 直接调用word的内建方法Dialogs()
统计中文字数:
Dialogs(wdDialogToolsWordCount).Execute
MsgBox Dialogs(wdDialogToolsWordCount). DBCs 或
MsgBox Dialogs(wdDialogToolsWordCount).SBCs