因为每个Word中图片的存在很影响对Word实际内容多少的判断,光从文件大小排列,无法直接看一下内容多的文档。
写一个vba脚本,遍历所有的文件,得到页码,显示输出。
需要知道每个文件的页数,并统计总页数,计算平均页数,可以用以下代码实现。
注:
一:关键的代码是Selection.Information(wdNumberOfPagesInDocument),通过该属性获得文档的页数。使用该属性前,最好将光标移动到文档的末尾,防止页数统计出错。
二:使用Word VBA,请手动百度如何使用Word VBA
以下为VBA代码,CSDN的识别真糟糕
Sub 统计一个文件夹下所有文档页数()
'统计一个文件夹下多个文档的页数,把统计结果都列入到一个txt文件中
'将光标移至文档末尾,为了防止页数统计出错
Dim myDoc As Document
Dim FolderPath As String, FileName As String
Dim i As Long, j As Long
Open "F:\userdata\Desktop\word版\记录文档1.txt" For Append As #1
FolderPath = "F:\userdata\Desktop\word版"
i = 0: j = 0
Application.ScreenUpdating = False
FileName = Dir(FolderPath)
Do While FileName <> ""
If Right(FileName, 4) = ".doc" Then
Set myDoc = Documents.Open(FolderPath & FileName) '文档赋值给mydoc
Selection.EndKey unit:=wdStory '将光标移至文档末尾,为了防止页数出错
i = i + Selection.Information(wdNumberOfPagesInDocument)
j = j + 1
Print #1, FileName & "的页数为" & Selection.Information(wdNumberOfPagesInDocument) & Chr(13) & Chr(10) '把文件名及其页数写入txt文件中
myDoc.Close False '无更改关闭
End If
FileName = Dir
Loop
Print #1, "共有" & j; "个文档" & Chr(13) & Chr(10) '
Print #1, "所有文档总页数为" & i & Chr(13) & Chr(10)
Print #1, "平均页数" & Fix(i / j) & Chr(13) & Chr(10)
Close #1
Application.ScreenUpdating = True
MsgBox "处理完成"
End Sub