|
楼主 |
发表于 2018-6-2 13:24
|
显示全部楼层
- Sub 第一章_选定区域()
- Dim i&, j$, k$, m$, n&, r As Range, s As Range, x&
- k = MsgBox("<是>:第一章 <否>:第一条 <取消>:自定义", 3 + 48)
- If k = vbYes Then
- j = "章"
- ElseIf k = vbNo Then
- j = "条"
- Else
- j = InputBox("请输入量词!" & vbCr & "(比如:第一节的<节>,第一部分的<部分>)", "第一章/第一条", "节")
- If j = "" Then End
- End If
- m = MsgBox("<是>:第一" & j & " <否>:第1" & j & " <取消>:放弃", 3 + 48, "请选择编号类型!")
- If m = vbYes Then
- n = 2
- ElseIf m = vbNo Then
- n = 1
- Else
- End
- End If
- With Selection
- If .Type = wdSelectionIP Then .WholeStory
- Set r = .Range
- Set s = .Range
- End With
- r.MoveStart 1, -1
- With r.Find
- .ClearFormatting
- .Replacement.Text = ""
- Do While .Execute("^13第[一二三四五六七八九十0-90-9百零〇○Oo千]{1,}" & j, , , 1, , , 1)
- x = 1
- With .Parent
- If Not .Information(12) Then
- .MoveStart 1, 1
- .Expand 4
- With .Find
- .Execute " ", , , 0, , , , , , "", 2
- .Execute " ", , , 0, , , , , , "", 2
- .Execute "^t", , , 0, , , , , , "", 2
- End With
- .Characters(InStr(.Text, j) + Len(j) - 1).InsertAfter Text:=Chr(-24159)
- If j = "条" Then
- If .Text Like "*[!。:;,、!?…—.:;,!?]?" Then .Characters.Last.InsertBefore Text:="。"
- .MoveEnd 1, -(Len(.Text) - InStr(.Text, j))
- With .Font
- .NameFarEast = "黑体"
- .NameAscii = "Times New Roman"
- .Bold = True
- End With
- Else
- .Style = wdStyleSubtitle
- If Len(j) > 1 Then .Font.Size = 18
- .Font.NameFarEast = "黑体"
- With .ParagraphFormat
- .SpaceBefore = 24
- .SpaceAfter = 24
- End With
- If .Text Like "*[。:;,、!?…—.:;,!?]?" Then .Characters.Last.Previous.Delete
- If .Text Like "* ???" Then .Characters.Last.Previous.InsertBefore Text:=Chr(-24159)
- .MoveEnd 1, -(Len(.Text) - (InStr(.Text, j) + Len(j) - 1))
- End If
- .MoveStart 1, 1
- .MoveEnd 1, -Len(j)
- i = i + 1
- .Text = i
- If n = 2 Then
- .Delete
- .Fields.Add Range:=r, Text:="= " & i & " \* CHINESENUM3"
- .Paragraphs(1).Range.Fields.Unlink
- End If
- .Expand 4
- r.SetRange Start:=r.End - 1, End:=s.End
- Else
- .Tables(1).Range.Next.Select
- With Selection
- If .End > s.End Then End
- If Asc(.Text) <> 13 Then .InsertParagraphBefore
- .Characters(1).Font.Size = 4
- r.SetRange Start:=.Start, End:=s.End
- End With
- End If
- End With
- Loop
- End With
- If x = 0 Then MsgBox "选定区域未找到<第一" & j & ">!!!", 0 + 16
- End Sub
复制代码 |
|