|
楼主 |
发表于 2019-1-21 09:57
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
翼★虎:下面 Title2345AutoNum 宏,我添加了两处取消域,分别是“标题2”、“标题3”段落,请将示例文档第一个标题2段落改为“九、XXX“,第一个标题3段落改为”(九)XXX“,试试此宏:
- Sub Title2345AutoNum()
- Dim doc As Document, r As Range, i As Paragraph, b&, c&, d&, e&
- Set doc = ActiveDocument
- With Selection
- .Expand 4
- .EndKey 6, 1
- Set r = .Range
- End With
- For Each i In r.Paragraphs
- With i.Range
- If Not .Information(12) Then
- If .Style = "标题 1" Or .Text Like "[!^13]附件*" Or .Text Like "附件*" Then
- b = 0: c = 0: d = 0: e = 0
- ElseIf .Style = "标题 2" Then
- c = 0: d = 0: e = 0
- b = b + 1
- With doc.Range(Start:=.Characters(1).Start, End:=.Characters(InStr(i.Range, "、")).End - 1)
- .Text = b
- .Delete
- .Fields.Add Range:=i.Range, Text:="= " & b & " \* CHINESENUM3"
- .Fields.Unlink
- End With
- ElseIf .Style = "标题 3" Then
- d = 0: e = 0
- c = c + 1
- With doc.Range(Start:=.Characters(1).Start, End:=.Characters(InStr(i.Range, ")")).End - 1)
- .Text = c
- .Delete
- .Fields.Add Range:=i.Range, Text:="= " & c & " \* CHINESENUM3"
- .Fields.Unlink
- .InsertBefore Text:="("
- End With
- ElseIf .Style = "标题 4" Then
- e = 0
- d = d + 1
- doc.Range(Start:=.Characters(1).Start, End:=.Characters(InStr(i.Range, ".")).End - 1).Text = d
- ElseIf .Style = "标题 5" Then
- e = e + 1
- With doc.Range(Start:=.Characters(1).Start, End:=.Characters(InStr(i.Range, ")")).End - 1)
- .Text = e
- .InsertBefore Text:="("
- End With
- End If
- End If
- End With
- Next
- ' doc.Fields.Unlink'删除全文域
- End Sub
复制代码 |
|