本帖最后由 wan12327 于 2017-11-7 11:07 编辑
各位老师好!我整理了多级列表的自动化编号代码。目前需要实现两个目标: A. 运行下列程序后,删除标题前方的文本编号,保留自动编号 B. 调整自动编号的缩进情况及与文本的间隔
以下是我整理的代码,希望老师给与指导:
Sub 多级列表设置() Dimi As Paragraph Call ListTitle(ActiveDocument) ForEach i In ActiveDocument.Paragraphs If i.Range Like "#.#.#.#*" = True And i.Range.Font.Bold = TrueThen i.Style = wdStyleHeading4 '标题4是以1.1.1.1的形式开头的段落 i.LineSpacing = LinesToPoints(1) i.SpaceAfter = 6 i.SpaceBefore = 12 i.Range.Font.Size = 11 ElseIf i.Range Like "#.#.#*" = True And i.Range.Font.Bold =True Then i.Style = wdStyleHeading3 '标题3是以1.1.1的形式开头的段落 i.LineSpacing = LinesToPoints(1) i.SpaceAfter = 6 i.SpaceBefore = 12 i.Range.Font.Size = 14 ElseIf i.Range Like "#.#*" = True And i.Range.Font.Bold = TrueThen i.Style = wdStyleHeading2 '标题2是以1.1形式开头的段落 i.LineSpacing = LinesToPoints(1) i.SpaceAfter = 6 i.SpaceBefore = 12 i.Range.Font.Size = 16 ElseIf i.Range Like "#*" = True And i.Range.Font.Bold = TrueThen i.Style = wdStyleHeading1 '标题1是以1形式开头的段落 i.LineSpacing = LinesToPoints(1) i.SpaceAfter = 6 i.SpaceBefore = 12 i.Range.Font.Size = 22 End If Next
End Sub
Sub ListTitle(doc As Document) DimLtTemp As ListTemplate, i As Integer SetLtTemp = doc.ListTemplates.Add(True) Fori = 1 To 4 With LtTemp.ListLevels(i) If i = 1 Then .NumberFormat = "%1": .NumberStyle = 0 If i = 2 Then .NumberFormat = "%1.%2": .NumberStyle = 0 If i = 3 Then .NumberFormat = "%1.%2.%3": .NumberStyle = 0 If i = 4 Then .NumberFormat = "%1.%2.%3.%4": .NumberStyle = 0 End With Next
End Sub |