|
Sub 多级列表样式运用()
Dim p As Range, doc As Document, s As Range
Set doc = ActiveDocument
Set p = IIf(Selection.Type = wdSelectionIP, doc.Content, Selection.Range)
If p = doc.Content Then
k = MsgBox("要进行全文处理吗?", vbYesNoCancel + vbQuestion, "全文处理判断")
If k <> vbYes Then Exit Sub
End If
With p.Find
.Execute "^11", , , 1, , , , 0, , "^p", 2
.Execute "^p^w", , , 0, , , , 0, , "^p", 2
.Execute "^w^p", , , 0, , , , 0, , "^p", 2
End With
sr$ = "〇一二三四五六七八九十百千万亿"
r1$ = "[" & sr & "]@、": r2$ = "[((][" & sr & "]@[))]"
r3$ = "[0-9]@[、..]": r4$ = "[((][0-9]@[))]"
a = Array(r1, r2, r3, r4)
Call ListTitle(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("s" & j + 2)
Else
.Move 4, 1
End If
End If
End With
Loop
End With
Next
p.ListFormat.ConvertNumbersToText
End Sub
Sub ListTitle(doc As Document)
Dim LtTemp As ListTemplate, i As Integer
Set LtTemp = doc.ListTemplates.Add(True)
On Error Resume Next
doc.Styles.Add Name:="s2", Type:=1
doc.Styles.Add Name:="s3", Type:=1
doc.Styles.Add Name:="s4", Type:=1
doc.Styles.Add Name:="s5", Type:=1
a = Array(6, 5, 2, 11)
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
.NumberPosition = InchesToPoints(0.1 * (i - 1))
.TextPosition = InchesToPoints(0 * i)
.LinkedStyle = "s" & i
doc.Styles("s" & i).Font.ColorIndex = a(i - 2)
End With
Next
End Sub |
|