ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 16098|回复: 24

[原创并分享]批量WROD文档格式比较报告程序

[复制链接]

TA的精华主题

TA的得分主题

发表于 2005-4-22 14:09 | 显示全部楼层 |阅读模式
应网友seenosee要求,作了一个小程序,希望能对大家有所帮助.

作为主题贴发表的目的,是便于以后检索.

适用于:根据标准文档对来自于指定文件夹中的学生WORD文档中的设置进行比较并签署报告的一个小程序,您需要在宏安全性为低的情况下使用该程序.

请修改其中的标准文档路径,注意"\".

您需要在OFFICE XP及以上版本中才能正确运行.

请运行该文档菜单栏右侧的"CompareFormat"命令.

比较范围:

1. 页面设置

1.1. 纸张大小

1.2. 纸型方向

1.3. 左页边距

1.4. 右页边距

1.5. 上页边距

1.6. 下页边距

2. 段落总数

3. 正文总长度

4. 错字指示

5. 正确率统计

6. 逐段落:

6.1. 字体大小

6.2. 字体名称

6.3. 字体颜色

6.4. 段前间距

6.5. 段后间距

6.6. 行距

6.7. 首行缩进

附:中文字体颜色函数,通过它,可以获得标准调色板中中文颜色名称.

相关链接:

http://club.excelhome.net/viewthread.php?tid=93920&extra=&page=1

http://club.excelhome.net/dispbbs.asp?BoardID=23&replyID=455897&id=86786&skin=0

tktDa95N.zip (23.47 KB, 下载次数: 536)
[此贴子已经被作者于2005-4-22 15:26:18编辑过]

eOLWpF6q.zip

23.28 KB, 下载次数: 412

[原创并分享]批量WROD文档格式比较报告程序

VpG5tWcb.zip

18.96 KB, 下载次数: 389

[原创并分享]批量WROD文档格式比较报告程序

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-22 14:10 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
'* +++++++++++++++++++++++++++++ '* Created By I Love You_Word!@ExcelHome 2005-4-22 15:26:47 '仅测试于System: Windows NT Word: 10.0 Language: 2052 '^The Code CopyIn [ThisDocument-ThisDocument]^' '* -----------------------------

Option Explicit Dim StandardFontColor As Long, WorkFontColor As Long Sub CompareFormat() Dim StandardDoc As Document, aDoc As Document, MyDialog As FileDialog, vrtSelectedItem As Variant Dim i As Paragraph, Worki As Paragraph, ParCount As Integer Dim StandardFontName As String, StandardFontSize As Single Dim WorkFontName As String, WorkFontSize As Single Dim StandardParLeftIndent As Single, StandardParLineSpacing As Single, StandardParSpaceAfter As Single Dim WorkParLeftIndent As Single, WorkParLineSpacing As Single, WorkParSpaceAfter As Single Dim StandardParSpaceBefore As Single, WorkParSpaceBefore As Single Dim StandardPageTop As Single, StandardPageBottom As Single, StandardPageLeft As Single, StandardPageRight As Single Dim WorkPageTop As Single, WorkPageBottom As Single, WorkPageLeft As Single, WorkPageRight As Single Dim StandardPaperSize As PageSetup, StandardPaperOrientation As Byte Dim WorkPaperSize As PageSetup, WorkPaperOrientation As Byte Dim aChar As Range, CharCount As Long, ErrCount As Long Dim ErrorText As String On Error Resume Next Set StandardDoc = Documents.Open(FileName:="E:\Word作业样板.Doc", Visible:=False) '定义一个文件夹选取对话框 Set MyDialog = Application.FileDialog(msoFileDialogFilePicker) With MyDialog .Filters.Clear '清除所有文件筛选器中的项目 .Filters.Add "所有 WORD 文件", "*.doc", 1 '增加筛选器的项目为所有WORD文件 .AllowMultiSelect = True '允许多项选择,可用SHIFT/CTRL进行选定 End With If MyDialog.Show = -1 Then '确定 Application.ScreenUpdating = False '关闭屏幕更新 For Each vrtSelectedItem In MyDialog.SelectedItems '在所有选取项目中循环 Set aDoc = Documents.Open(FileName:=vrtSelectedItem, Visible:=False) ' MsgBox "Selected item's path: " & vrtSelectedItem ParCount = 0: CharCount = 0: ErrCount = 0 '初始化变量 With aDoc ErrorText = Chr(13) & "文档名:" & .Name & "文档作者:" & .BuiltInDocumentProperties("Author") & Chr(13) ''''''标准文档获得页边距 With StandardDoc.PageSetup StandardPaperSize = .PaperSize StandardPaperOrientation = .Orientation StandardPageTop = VBA.Round(.TopMargin, 2) StandardPageBottom = VBA.Round(.BottomMargin, 2) StandardPageLeft = VBA.Round(.LeftMargin, 2) StandardPageRight = VBA.Round(.RightMargin, 2) End With '''''获得作业文档的页边距 With .PageSetup WorkPaperSize = .PaperSize WorkPaperOrientation = .Orientation WorkPageTop = VBA.Round(.TopMargin, 2) WorkPageBottom = VBA.Round(.BottomMargin, 2) WorkPageLeft = VBA.Round(.LeftMargin, 2) WorkPageRight = VBA.Round(.RightMargin, 2) End With ''''''''''''''''''''''''''''''''''比较页面设置 If StandardPaperSize <> WorkPaperSize Then ErrorText = ErrorText & "纸张大小不一致" & Chr(13) If StandardPaperOrientation <> WorkPaperOrientation Then ErrorText = ErrorText & "纸型方向不一致" & Chr(13) If StandardPageTop <> WorkPageTop Then ErrorText = ErrorText & "上页边距不符,应为" & StandardPageTop & "实为" & WorkPageTop & Chr(13) If StandardPageBottom <> WorkPageBottom Then ErrorText = ErrorText & "下页边距不符,应为" & StandardPageBottom & "实为" & WorkPageBottom & Chr(13) If StandardPageLeft <> WorkPageLeft Then ErrorText = ErrorText & "左页边距不符,应为" & StandardPageLeft & "实为" & WorkPageLeft & Chr(13) If StandardPageRight <> WorkPageRight Then ErrorText = ErrorText & "右页边距不符,应为" & StandardPageRight & "实为" & WorkPageRight & Chr(13) For Each Worki In .Paragraphs ParCount = ParCount + 1 '''''取得段落格式 With StandardDoc.Paragraphs(ParCount).Format StandardParLeftIndent = .FirstLineIndent StandardParLineSpacing = .LineSpacing StandardParSpaceAfter = .SpaceAfter StandardParSpaceBefore = .SpaceBefore End With '''取得字体格式 With StandardDoc.Paragraphs(ParCount).Range StandardFontName = .Font.NameFarEast StandardFontSize = .Font.Size StandardFontColor = .Font.Color End With ''''取得段落格式 With Worki.Format WorkParLeftIndent = .FirstLineIndent WorkParLineSpacing = .LineSpacing WorkParSpaceAfter = .SpaceAfter WorkParSpaceBefore = .SpaceBefore End With ''''取得字体格式 With Worki.Range WorkFontName = .Font.NameFarEast WorkFontSize = .Font.Size WorkFontColor = .Font.Color End With '''''''''''''''''''''''''''''比较段落格式 If StandardParLeftIndent <> WorkParLeftIndent Then ErrorText = ErrorText & "第" & ParCount & "段落首行缩进不符,应为" & StandardParLeftIndent & "实为" & WorkParLeftIndent & Chr(13) If StandardParLineSpacing <> WorkParLineSpacing Then ErrorText = ErrorText & "第" & ParCount & "行间距不符,应为" & StandardParLineSpacing & "实为" & WorkParLineSpacing & Chr(13) If StandardParSpaceAfter <> WorkParSpaceAfter Then ErrorText = ErrorText & "第" & ParCount & "段后间距不符,应为" & StandardParSpaceAfter & "实为" & WorkParSpaceAfter & Chr(13) If StandardParSpaceBefore <> WorkParSpaceBefore Then ErrorText = ErrorText & "第" & ParCount & "段前间距不符,应为" & StandardParSpaceBefore & "实为" & WorkParSpaceBefore & Chr(13) '''''''''''''''''''''''''''''比较字体格式 If StandardFontName <> WorkFontName Then ErrorText = ErrorText & "第" & ParCount & "段落中中文字体不符,应为" & StandardFontName & "实为" & WorkFontName & Chr(13) If StandardFontSize <> WorkFontSize Then ErrorText = ErrorText & "第" & ParCount & "段落中中文字体字号不符,应为" & StandardFontSize & "实为" & WorkFontSize & Chr(13) If StandardFontColor <> WorkFontColor Then ErrorText = ErrorText & "第" & ParCount & "段落中中文字体颜色不符,应为" & GetStandardFontColor & "实为" & GetWorkFontColor & Chr(13) Next Worki For Each aChar In .Characters '在作业文档的字中循环 CharCount = CharCount + 1 '计数 If aChar <> StandardDoc.Characters(CharCount) Then '比较 ErrCount = ErrCount + 1 '计数 aChar.Font.StrikeThrough = True '删除线 aChar.Font.Color = wdColorRed '红色字体 End If Next aChar ErrorText = ErrorText & "标准文档段落总数为" & StandardDoc.Paragraphs.Count & ",此文档段落总数为" & .Paragraphs.Count & Chr(13) ErrorText = ErrorText & "标准文档全长" & StandardDoc.Content.End & ",此文档全长" & .Content.End & Chr(13) ErrorText = ErrorText & "录入文字正确率:" & .Characters.Count - ErrCount & "/" & .Characters.Count & "=" & VBA.Round(((.Characters.Count - ErrCount) / .Characters.Count * 100), 2) & "%" & Chr(13) ErrorText = ErrorText & Application.UserName & Now & Chr(13) ErrorText = ErrorText & "*******************************************************" ThisDocument.Content.InsertAfter ErrorText .Content.InsertAfter ErrorText .Close True '保存文档(内含批改记录) End With Next vrtSelectedItem StandardDoc.Close False Application.ScreenUpdating = True '恢复屏幕更新 MsgBox "全部文档检查完毕,请核查!", vbOKOnly + vbExclamation End If End Sub '---------------------- Function GetStandardFontColor() As String Select Case StandardFontColor Case Is = -16777216 GetStandardFontColor = "自动色" Case Is = 0 GetStandardFontColor = "黑色" Case Is = 13209 GetStandardFontColor = "褐色" Case Is = 13107 GetStandardFontColor = "橄榄绿" Case Is = 13056 GetStandardFontColor = "深绿" Case Is = 6697728 GetStandardFontColor = "深灰蓝" Case Is = 8388608 GetStandardFontColor = "深蓝" Case Is = 10040115 GetStandardFontColor = "靛蓝" Case Is = 3355443 GetStandardFontColor = "灰色-80%" Case Is = 128 GetStandardFontColor = "深红" Case Is = 26367 GetStandardFontColor = "桔黄" Case Is = 32896 GetStandardFontColor = "深黄" Case Is = 32768 GetStandardFontColor = "绿色" Case Is = 8421376 GetStandardFontColor = "蓝绿色" Case Is = 16711680 GetStandardFontColor = "蓝色" Case Is = 10053222 GetStandardFontColor = "蓝-灰" Case Is = 8421504 GetStandardFontColor = "灰色-50%" Case Is = 255 GetStandardFontColor = "红色" Case Is = 39423 GetStandardFontColor = "浅桔黄" Case Is = 52377 GetStandardFontColor = "酸橙色" Case Is = 6723891 GetStandardFontColor = "海绿" Case Is = 13421619 GetStandardFontColor = "宝石蓝" Case Is = 16737843 GetStandardFontColor = "浅蓝" Case Is = 8388736 GetStandardFontColor = "紫色" Case Is = 10066329 GetStandardFontColor = "灰色-40%" Case Is = 16711935 GetStandardFontColor = "粉红" Case Is = 52479 GetStandardFontColor = "金色" Case Is = 65535 GetStandardFontColor = "黄色" Case Is = 65280 GetStandardFontColor = "鲜绿" Case Is = 16776960 GetStandardFontColor = "青绿" Case Is = 16763904 GetStandardFontColor = "天蓝" Case Is = 6697881 GetStandardFontColor = "梅红" Case Is = 12632256 GetStandardFontColor = "灰色" Case Is = 13408767 GetStandardFontColor = "玫瑰红" Case Is = 10079487 GetStandardFontColor = "棕黄" Case Is = 10092543 GetStandardFontColor = "浅黄" Case Is = 13434828 GetStandardFontColor = "浅绿" Case Is = 16777164 GetStandardFontColor = "浅青绿" Case Is = 16764057 GetStandardFontColor = "淡蓝" Case Is = 16751052 GetStandardFontColor = "淡紫" Case Is = 16777215 GetStandardFontColor = "白色" End Select End Function '---------------------- Function GetWorkFontColor() As String Select Case WorkFontColor Case Is = -16777216 GetWorkFontColor = "自动色" Case Is = 0 GetWorkFontColor = "黑色" Case Is = 13209 GetWorkFontColor = "褐色" Case Is = 13107 GetWorkFontColor = "橄榄绿" Case Is = 13056 GetWorkFontColor = "深绿" Case Is = 6697728 GetWorkFontColor = "深灰蓝" Case Is = 8388608 GetWorkFontColor = "深蓝" Case Is = 10040115 GetWorkFontColor = "靛蓝" Case Is = 3355443 GetWorkFontColor = "灰色-80%" Case Is = 128 GetWorkFontColor = "深红" Case Is = 26367 GetWorkFontColor = "桔黄" Case Is = 32896 GetWorkFontColor = "深黄" Case Is = 32768 GetWorkFontColor = "绿色" Case Is = 8421376 GetWorkFontColor = "蓝绿色" Case Is = 16711680 GetWorkFontColor = "蓝色" Case Is = 10053222 GetWorkFontColor = "蓝-灰" Case Is = 8421504 GetWorkFontColor = "灰色-50%" Case Is = 255 GetWorkFontColor = "红色" Case Is = 39423 GetWorkFontColor = "浅桔黄" Case Is = 52377 GetWorkFontColor = "酸橙色" Case Is = 6723891 GetWorkFontColor = "海绿" Case Is = 13421619 GetWorkFontColor = "宝石蓝" Case Is = 16737843 GetWorkFontColor = "浅蓝" Case Is = 8388736 GetWorkFontColor = "紫色" Case Is = 10066329 GetWorkFontColor = "灰色-40%" Case Is = 16711935 GetWorkFontColor = "粉红" Case Is = 52479 GetWorkFontColor = "金色" Case Is = 65535 GetWorkFontColor = "黄色" Case Is = 65280 GetWorkFontColor = "鲜绿" Case Is = 16776960 GetWorkFontColor = "青绿" Case Is = 16763904 GetWorkFontColor = "天蓝" Case Is = 6697881 GetWorkFontColor = "梅红" Case Is = 12632256 GetWorkFontColor = "灰色" Case Is = 13408767 GetWorkFontColor = "玫瑰红" Case Is = 10079487 GetWorkFontColor = "棕黄" Case Is = 10092543 GetWorkFontColor = "浅黄" Case Is = 13434828 GetWorkFontColor = "浅绿" Case Is = 16777164 GetWorkFontColor = "浅青绿" Case Is = 16764057 GetWorkFontColor = "淡蓝" Case Is = 16751052 GetWorkFontColor = "淡紫" Case Is = 16777215 GetWorkFontColor = "白色" End Select End Function '----------------------

[此贴子已经被作者于2005-4-22 15:27:26编辑过]

TA的精华主题

TA的得分主题

发表于 2005-4-22 14:27 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

做得太棒啦!

这个程序很有实用价值!

多谢守柔版主的辛勤劳动和无私奉献!

建议加为精华帖!!!

TA的精华主题

TA的得分主题

发表于 2005-4-23 14:25 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

敬爱的守柔版主,您好!

经过我反复测试,发现您的这个程序还有一点小问题,麻烦您查看一下。

这是程序运行前各文档:

Xv04TI9h.rar (38.42 KB, 下载次数: 109)

麻烦您查看,谢谢!

ss1SW9OO.rar

34.42 KB, 下载次数: 91

[原创并分享]批量WROD文档格式比较报告程序

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-23 15:24 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

请恢复原来的两个文档中的格式设置(去除下划线等)

请注意,你的程序没有正确运行,你可以退出WORD后重启WORD,再行测试:

注意,这是我用你的测试前的主文档,进行测试的结果,和你的测试后的主文档中的测试结果,其中,你的测试后结果没有包含总段落数和文档总长度.

文档名:A10.doc文档作者:I Love You_Word!

纸张大小不一致

上页边距不符,应为72实为101.25

左页边距不符,应为90实为110.25

……

标准文档段落总数为9,此文档段落总数为7

标准文档全长213,此文档全长178

录入文字正确率:175/178=98.31%

I Love You_Word!2005-4-23 15:17:25

*******************************************************

文档名:A101.doc文档作者:极地组织

纸张大小不一致

……

标准文档段落总数为9,此文档段落总数为7

标准文档全长213,此文档全长178

录入文字正确率:178/178=100%

I Love You_Word!2005-4-23 15:17:29

*******************************************************

文档名:A101.doc文档作者:极地组织

纸张大小不一致

上页边距不符,应为0实为72

下页边距不符,应为0实为72

左页边距不符,应为0实为90

右页边距不符,应为0实为90

……

录入文字正确率:0/178=0%

dyg2005-4-23 14:14:28

*******************************************************

文档名:A10.doc文档作者:I Love You_Word!

纸张大小不一致

上页边距不符,应为0实为101.25

下页边距不符,应为0实为72

左页边距不符,应为0实为110.25

右页边距不符,应为0实为90

……

录入文字正确率:0/178=0%

dyg2005-4-23 14:14:30

******************************************************

请重新运行程序。

TA的精华主题

TA的得分主题

发表于 2005-4-23 16:51 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

谢谢守柔版主热情回复,

经过我反复测试,发现您的这个程序还有一点小问题,麻烦您再查看一例。

这是程序运行前各文档:

WTC6BRwY.rar (36.16 KB, 下载次数: 66) 为什么有时作业文档稍微改变一点,测试结果就会出错呢?

麻烦守柔版主测试!

ljJkaHcw.rar

34.33 KB, 下载次数: 66

[原创并分享]批量WROD文档格式比较报告程序

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-24 06:48 | 显示全部楼层

我粗粗看了一下,你是指A10文档的正确率吧?

WORD在比较时,不会跟人一样,大部分正确而正确率高,就象你在练习打字时,如果某一个字开始,你少录入了一个字,其后面的文字是正确的,但位置错误了,所以,还是错误了,程序是按照标准文档的字符位置,哪怕作业文档多了一个空格,或者少了一个空格,则正确率肯定是不高的,除非在文档最后处。

TA的精华主题

TA的得分主题

发表于 2005-4-24 09:29 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

哦,谢谢守柔朋友的热情回复!

嗯,我还好好想想!

昨晚是一个不眠之夜!

[em06]

TA的精华主题

TA的得分主题

发表于 2005-6-23 15:03 | 显示全部楼层
以下是引用守柔在2005-4-24 6:48:00的发言:

我粗粗看了一下,你是指A10文档的正确率吧?

WORD在比较时,不会跟人一样,大部分正确而正确率高,就象你在练习打字时,如果某一个字开始,你少录入了一个字,其后面的文字是正确的,但位置错误了,所以,还是错误了,程序是按照标准文档的字符位置,哪怕作业文档多了一个空格,或者少了一个空格,则正确率肯定是不高的,除非在文档最后处。

能否不对比标准文档的字符位置,只对比字符呢?该怎么改代码呢?急盼回复!

TA的精华主题

TA的得分主题

发表于 2007-6-6 18:02 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
请问,再次新建文档时文档中出现了原来的比较内容,怎么回事?如何消除这种现象?
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-17 07:25 , Processed in 0.040774 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表