|
413191246se 老师好,我看了你以前的帖子,有一篇关于序号连续判断的帖子,借鉴杜先生的帖子做了修改基本达到了目的。我增加了序号转文本后,标题为“1.XX,2.XX”时候,全篇连续编排,不会被“一、XX,二、XX”及“(一)XX 、(二)、XX”打断重拍。另外,标题与正文不分段时候会整段识别为标题“(二)主要目标。进一步明确规范……”→ “(二)主要目标。进一步明确规范……”最近电脑无法上传附件,沟通起来稍显不便,老师见谅。
- Sub Title2345AutoNum()
- Dim a, b, j&, ksr$, x&, sr$, r1$, r2$, r3$, r4$
- Call ListTitle(ActiveDocument)
- ActiveDocument.content.Find.Execute "^11", , , 1, , , , , , "^p", 2
- ActiveDocument.content.Find.Execute "^p^w", , , 0, , , , , , "^p", 2
- sr$ = "〇一二三四五六七八九十百千万亿"
- r1$ = "[" & sr & "]@、": r2$ = "[((][" & sr & "]@[))]"
- r3$ = "[0-9]@[、..]": r4$ = "[((][0-9]@[))]"
- a = Array(r1, r2, r3, r4)
- b = Array("标题 2", "标题 3", "标题 4", "标题 5")
- For j = 0 To UBound(a)
- With ActiveDocument.content.Find
- Do While .Execute(a(j), , , 1)
- 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("" & b(j) & "")
- Else
- .Move 4, 1
- End If
- End If
- End With
- Loop
- ActiveDocument.content.ListFormat.ConvertNumbersToText
- End With
- Next
- End Sub
-
- Sub ListTitle(doc As Document)
- Dim LtTemp As ListTemplate, i As Integer, a
- Set LtTemp = doc.ListTemplates.Add(True)
- 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.2 * (i - 1))
- .TextPosition = InchesToPoints(0.2 * i)
- .LinkedStyle = "标题 " & i
- doc.Styles("标题 " & i).Font.ColorIndex = a(i - 2)
- doc.Fields.Update
- doc.Fields.Unlink
- End With
- Next
- End Sub
复制代码
|
|