本帖最后由 13907933959 于 2017-8-29 15:27 编辑
由于还是个门外汉,花了近13个小时,好象可以实现楼主的意图了。真诚欢迎论坛上的各位前辈帮助纠错、优化、简化代码!谢谢!
Sub 删除重复的标题() '把文档内所有两个重复的第几章标题删除一个,删除标题的下划线,标题另起一行并居中。 Selection.WholeStory Selection.Font.Underline = wdUnderlineNone Selection.MoveUp Unit:=wdLine, Count:=1 With ActiveDocument.Content.Find .Execute "第[0-9]{1,5}章:(*)第", , , 1, , , , , , "第", 2 End With With ActiveDocument.Content.Find .Font.Size = 15 .Execute , , , , , , , , 1, "^p^&^p", 2 End With With ActiveDocument.Content.Find .Execute "^13^13", , , 1, , , , , , "^p", 2 End With With ActiveDocument.Content.Find .Font.Size = 15 .Replacement.Font.Size = 10.5 .Execute "^13", , , 1, , , , , , "^p", 2 End With Dim i As Paragraph For Each i In ActiveDocument.Paragraphs If i.Range.Characters(1) = "第" Then i.Style =ActiveDocument.Styles(wdStyleSubtitle) With i.Range With .Font .Name = "宋体" .Bold = False .Size = 15 .Color = wdColorBlack End With End With End If Next With Selection .HomeKey wdStory With .Find .ClearFormatting .Font.Size = 15 .Format = True End With .Find.Execute End With Application.Run "SelectSimilarFormatting" With Selection.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.MoveUp Unit:=wdLine, Count:=1 End Sub
|