|
可试试:- Sub test()
- Dim i As Integer
- Dim myListTemplate As ListTemplate
-
- Set myListTemplate = ListGalleries(wdOutlineNumberGallery).ListTemplates(1)
- For i = 1 To 4
- With myListTemplate.ListLevels(i)
- .NumberFormat = Choose(i, "%1.", "%1.%2", "%1.%2.%3", "%4.")
- .TrailingCharacter = wdTrailingTab
- .NumberStyle = wdListNumberStyleArabic
- .NumberPosition = CentimetersToPoints(0)
- .Alignment = wdListLevelAlignLeft
- .TextPosition = 21
- .ResetOnHigher = True
- .StartAt = 1
- End With
- Next
-
- i = 0
- Application.ScreenUpdating = False
- With ActiveDocument.Content.Find
- .Text = "[0-9][0-9.]@[^9^32]"
- .MatchWildcards = True
- Do While .Execute = True
- With .Parent '假设1级手动编号在表外,2-4级编号均在表内第1列,否则不处理
- If .Information(wdWithInTable) = False And .Start = .Paragraphs(1).Range.Start And Right(.Text, 2) = "." & vbTab Then
- i = i + ApplyListTemp(.Duplicate, myListTemplate, 1)
- ElseIf .Information(wdWithInTable) = True And .Start = .Paragraphs(1).Range.Start And UBound(Split(.Text, ".")) = 1 Then
- If Right(.Text, 2) = ". " And .Cells(1).ColumnIndex = 1 Then
- i = i + ApplyListTemp(.Duplicate, myListTemplate, 4)
- ElseIf .Cells(1).ColumnIndex = 1 Then
- i = i + ApplyListTemp(.Duplicate, myListTemplate, 2)
- End If
- ElseIf .Information(wdWithInTable) = True And .Start = .Paragraphs(1).Range.Start And UBound(Split(.Text, ".")) = 2 Then
- If .Cells(1).ColumnIndex = 1 Then i = i + ApplyListTemp(.Duplicate, myListTemplate, 3)
- End If
- End With
- Loop
- End With
- Application.ScreenUpdating = True
- MsgBox "共修改了" & i & "个段落", vbInformation
- End Sub
- Function ApplyListTemp(myRange As Range, LT As ListTemplate, i As Integer) As Integer
- With myRange
- .ListFormat.ApplyListTemplateWithLevel LT, True, wdListApplyToWholeList, wdWord10ListBehavior, i
- .Paragraphs(1).Range.HighlightColorIndex = wdYellow
- ' .Text = Empty '删除原非自动编号
- End With
- ApplyListTemp = 1
- End Function
复制代码
|
|