|
楼主必须会用VBA宏,如果不会请百度。下面是 本坛大神 杜先生 前一段写的代码,能把各级标题设置为自动编号:
- Sub 多级列表样式运用()
- Dim p As Range, doc As Document, s As Range, sr$, r1$, r2$, r3$, r4$, a, j&, x&, ksr$
- Set doc = ActiveDocument
- Set p = IIf(Selection.Type = wdSelectionIP, doc.Content, Selection.Range)
- sr$ = "一二三四五六七八九十百零千〇"
- r1$ = "[" & sr & "]@、": r2$ = "[((][" & sr & "]@[))]": r3$ = "[0-9]@[、..]": r4$ = "[((][0-9]@[))]"
- a = Array(r1, r2, r3, r4)
- Call ListTitles(doc)
- For j = 0 To UBound(a)
- Set s = p.Duplicate
- With s.Find
- Do While .Execute(a(j), , , 1)
- If Not s.InRange(p) Then Exit Do
- With .Parent
- If Not .Information(wdWithInTable) Then
- x = Len(.Text): ksr = .Text
- .Expand 4: .Collapse
- If .MoveWhile(ksr, x) = x Then
- .MoveStart , -x: .Text = Empty
- .Style = ActiveDocument.Styles("标题 " & j + 2)
- Else
- .Move 4, 1
- End If
- End If
- End With
- Loop
- End With
- Next
- p.ListFormat.ConvertNumbersToText
- End Sub
- Sub ListTitles(doc As Document)
- Dim LtTemp As ListTemplate, i%, a
- Set LtTemp = doc.ListTemplates.Add(True)
- On Error Resume Next
- a = Array(6, 5, 11, 12)
- For i = 2 To 5
- With LtTemp.ListLevels(i)
- If i = 2 Then .NumberFormat = "%2、": .NumberStyle = 37
- If i = 3 Then .NumberFormat = "(%3)": .NumberStyle = 37
- If i = 4 Then .NumberFormat = "%4.": .NumberStyle = 0
- If i = 5 Then .NumberFormat = "(%5)": .NumberStyle = 0
- .TrailingCharacter = 2: .StartAt = 1: .ResetOnHigher = True
- .LinkedStyle = "标题 " & i
- doc.Styles("标题 " & i).Font.ColorIndex = a(i - 2)
- End With
- Next
- End Sub
复制代码 |
|