|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
按楼主新要求增加了处理小写字母编号部分,可试试。
原代码本来就提供了删除原自动编号的代码行,只是为了方便对照而将其注释掉。
该自动编号是多级的,会根据其前一级依次自动重新编号。因文档前面目前中有符合编号格式的段落,程序会将其处理,楼主可手动取消其自动编号。
建议楼主多了解一引起使用宏的知识,当然最好能读懂甚至会写一点,或修改一下。- Sub test()
- Dim i As Integer
- Dim myListTemplate As ListTemplate
-
- Set myListTemplate = ListGalleries(wdOutlineNumberGallery).ListTemplates(1)
- For i = 1 To 5
- With myListTemplate.ListLevels(i)
- .NumberFormat = Choose(i, "%1.", "%1.%2", "%1.%2.%3", "%4.", "%5.")
- .TrailingCharacter = wdTrailingTab
- .NumberStyle = IIf(i < 5, 0, 4)
- .NumberPosition = 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
-
- .Parent.WholeStory '处理表格内首列的手动小写字母编号
- .Text = "[a-z].^9"
- Do While .Execute = True
- With .Parent
- If .Information(wdWithInTable) = True And .Start = .Paragraphs(1).Range.Start Then _
- If .Cells(1).ColumnIndex = 1 Then i = i + ApplyListTemp(.Duplicate, myListTemplate, 5)
- 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
复制代码 |
评分
-
1
查看全部评分
-
|