Sub 标题正文()
' 获取当前选定区域的文本范围
Set doc = ActiveDocument
Dim rng As Range
Dim page_number As Integer
page_number = InputBox("请输入起始页码:", "起始页码", 1)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=Number
Set rng = Selection.Range.Duplicate
rng.End = doc.Range.End
' 获取列表的层级
Dim para As Paragraph
For Each para In rng.Paragraphs
' 检查段落是否为标题样式(例如标题1、标题2等)
If para.OutlineLevel = 1 Then ' 一级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 1")
ElseIf para.OutlineLevel = 2 Then ' 二级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 2")
ElseIf para.OutlineLevel = 3 Then ' 三级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 3")
ElseIf para.OutlineLevel = 4 Then ' 四级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 4")
ElseIf para.OutlineLevel = 5 Then ' 五级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 5")
ElseIf para.OutlineLevel = 6 Then ' 六级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 6")
ElseIf para.OutlineLevel = 7 Then ' 七级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 7")
ElseIf para.OutlineLevel = 8 Then ' 八级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 8")
ElseIf para.OutlineLevel = 9 Then ' 九级标题
para.Range.Font.Bold = False
para.Range.Style = ActiveDocument.Styles("GJB标题 9")
End If
Next para
MsgBox "标题样式已修改完毕。", vbInformation, "操作完成"
End Sub
使用宏脚本,批量设置Word的标题样式
最新推荐文章于 2024-08-16 22:26:34 发布