vba 统计Word 字数、页数等信息
来源:互联网 发布:淘宝上靠谱mk代购 编辑:程序博客网 时间:2024/05/17 09:00
方法一. 使用.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
- vba 统计Word 字数、页数等信息
- VBA 字数统计
- Interop统计WORD字数
- OPENXML获取DOCX中的页数和字数统计
- linux下wc统计文件的个数、行数、字数、字节数等信息
- 比word先进的字数统计
- .NET实现ms-Word中字数统计
- 多个Word文档总页数的快速统计技巧
- Word字数统计怎么用?2003/2007/2010统计字数全攻略!
- 用VBA取得WORD当前光标所在位置的行号列号和页数
- 不启动Word查看文档字数统计的方法
- 字数统计
- 字数统计
- 字数统计
- 获取Word的页数
- 如何去掉百度编辑器 ueditor 元素路径、字数统计等
- 统计页数(水)
- 一个统计Word文档中行数的VBA例程
- 我的游戏之路(7)
- PC 上访问设备数据库的方法
- POJ2503
- XML解析
- apt-get 使用指南
- vba 统计Word 字数、页数等信息
- ASP.NET+ExtJs4.0+FieldContainer的用法
- C++左值和右值
- (转)c# process类的使用
- sql loader 参数详解
- [观点]给年轻程序员的几句话
- [青海、甘南之行散记] 当风吹过高原,一颗心在说话
- 潜心搞研究
- 网络字节序与主机字节序