|
本帖最后由 413191246se 于 2020-8-15 12:48 编辑
* 应用本宏前,请一定要进行公文排版或普通排版(因为“第”字前有空格会找不到)。
* 既可添加"节/课/题/阶段/自然段"等量词;也可将n=0改为n=1查找《第1章》格式。
* 亮点:无论第一章/第一条/第一部分,均可自动设置格式、自动编号,无需手动。
- Sub 第一章()
- '集成扩展宏/第1行可添加<节/课/题/阶段/自然段>等/第3行若n=1将查找<第1章>
- Const s As String = "章/条/部分"
- Dim arr, i&, j&, n&
- n = 0
- arr = Split(s, "/")
- For j = 0 To UBound(arr)
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Text = "^13第[一二三四五六七八九十百零千〇○OoOo0-90-9]@" & arr(j)
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- i = i + 1
- With .Parent
- With ActiveDocument.Range(Start:=.Start + 1, End:=.End - Len(arr(j)))
- .Delete
- If n = 0 Then
- .Fields.Add Range:=.Paragraphs(1).Range, Text:="= " & i & " \* CHINESENUM3"
- .Fields.Unlink
- Else
- .InsertBefore Text:=i
- End If
- .InsertBefore Text:="第"
- With .Paragraphs(1).Range
- With .Find
- .Execute "^w", , , , , , , , , "", 2
- .Execute " ", , , , , , , , , "", 2
- End With
- .Characters(InStr(.Text, arr(j)) + Len(arr(j)) - 1).InsertAfter Text:=Chr(-24159)
- If arr(j) = "条" Then
- If .Text Like "*[!。]?" Then .Characters.Last.InsertBefore Text:="。"
- With ActiveDocument.Range(Start:=.Start, End:=.Characters(InStr(.Text, arr(j))).End).Font
- .NameFarEast = "黑体"
- .NameAscii = "Times New Roman"
- .Bold = True
- .Color = wdColorPink
- End With
- Else
- If .Text Like "*。?" Then .Characters.Last.Previous.Delete
- If Len(.Text) - (InStr(.Text, arr(j)) + Len(arr(j)) - 1) = 4 Then .Characters.Last.Previous.InsertBefore Text:=Chr(-24159)
- With .Font
- .NameFarEast = "黑体"
- .NameAscii = "Arial"
- .Size = 16
- .Bold = True
- If j = 0 Then
- .Color = wdColorRed
- Else
- .Color = wdColorGreen
- If Len(arr(j)) > 1 Then .Size = 18
- End If
- End With
- With .ParagraphFormat
- .CharacterUnitFirstLineIndent = 0
- .FirstLineIndent = CentimetersToPoints(0)
- .Alignment = wdAlignParagraphCenter
- .SpaceBefore = 30
- .SpaceAfter = 24
- End With
- End If
- End With
- End With
- End With
- Loop
- End With
- i = 0
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|