|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
楼主,duquancai(段全才)朋友出手了,我本不该出手,他是高手!但我也费心编了一个宏,请楼主一试:(请将此宏复制一下,然后在 Word 2003 中,按 Alt+F11 打开 VBE 编程环境,再按 Ctrl+End 将光标移到所有编码末尾,粘贴代码后关闭 VBE,然后打开楼主的文档(请注意备份),按 Alt+F8 打开宏列表,找到本宏名 test,然后按“运行”按钮即可,请注意提示!处理完毕注意抽查!)
- Sub test()
- If MsgBox("请确认你的 Word 2003 文档中,头几个字符就是<准考证号……>,否则会出错!处理完毕后请自行抽查!" & vbCr & "是否继续?", vbYesNo + vbCritical) = vbNo Then End
- 'Sub 删除手动换行符和假段落标记()
- ActiveDocument.Content.Find.Execute findtext:="^l", replacewith:="^p", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="^13", replacewith:="^p", Replace:=wdReplaceAll
- 'Sub 删除空行()
- Dim i As Paragraph
- For Each i In ActiveDocument.Paragraphs
- If Len(i.Range) = 1 Then i.Range.Delete
- Next
- '替换
- ActiveDocument.Content.Find.Execute findtext:="含听力 ", replacewith:="含听力", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="^p市级评价科目", replacewith:=" 市级评价科目", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:=":", replacewith:=":", Replace:=wdReplaceAll
- '循环遍历每个段落
- Selection.HomeKey Unit:=wdStory
- For Each i In ActiveDocument.Paragraphs
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(findtext:=" 准考证号", Forward:=True)
- Do
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- Loop Until Selection Like "*市级"
- Exit Do
- Loop
- Selection.MoveEnd Unit:=wdCharacter, Count:=-2
- Selection.Cut
- Selection.Find.Execute findtext:="//", Forward:=True
- Selection.Paste
- i.Range.Characters.First.Copy
- Next
- '替换
- ActiveDocument.Content.Find.Execute findtext:="//", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="市级评价科目", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:=" 准考证号", replacewith:="^p准考证号", Replace:=wdReplaceAll
- 'Sub 删除段落首尾空格()--'全选/居中/两端对齐
- Selection.WholeStory
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- '套进表格(以空格为界)
- Selection.WholeStory
- Selection.ConvertToTable Separator:=4, NumColumns:=10, NumRows:=12, _
- AutoFitBehavior:=wdAutoFitFixed
- With Selection.Tables(1)
- If .Style <> "网格型" Then
- .Style = "网格型"
- End If
- .ApplyStyleHeadingRows = True
- .ApplyStyleLastRow = True
- .ApplyStyleFirstColumn = True
- .ApplyStyleLastColumn = True
- End With
- '替换
- ActiveDocument.Content.Find.Execute findtext:="准考证号:", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="考生号:", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="姓名:", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="总分", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="语文:", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="数学:", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="外语:", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="理化:", replacewith:="", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute findtext:="政史:", replacewith:="", Replace:=wdReplaceAll
- '
- Selection.InsertRowsAbove 1
- Selection.TypeText Text:="准考证号"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="考生号"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="姓名"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="总分"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="语文"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="数学"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="外语"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="理化"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="政史"
- Selection.MoveRight Unit:=wdCell
- Selection.TypeText Text:="此列删除"
- Selection.Tables(1).Select
- MsgBox "处理完毕!!!!!!" & vbCr & "请手工剪切到 Excel 中,并删除最后一列!", vbOKOnly + vbExclamation
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|