|
楼主说话不严密!每个段落包括一至多个句子,到底是查找句子还是段落呢?请参看我下面的代码:
- Sub Title2345Auto()
- Dim i As Paragraph, s As Long, t As Long, f As Long, v As Long
- For Each i In ActiveDocument.Paragraphs
- If i.Range Like "[一二三四五六七八九十]、*" Or i.Range Like "[一二三四五六七八九十][一二三四五六七八九十百]、*" Or i.Range Like "[二三四五六七八九]十[一二三四五六七八九]、*" Or i.Range Like "[一二三四五六七八九]百[一二三四五六七八九零][一二三四五六七八九十]、*" Or i.Range Like "[一二三四五六七八九]百[一二三四五六七八九]十[一二三四五六七八九]、*" Then
- If i.Range.Sentences.Count = 1 Then s = 1 Else s = 2
- ElseIf i.Range Like "([一二三四五六七八九十])*" Or i.Range Like "([一二三四五六七八九十][一二三四五六七八九十百])*" Or i.Range Like "([二三四五六七八九]十[一二三四五六七八九])*" Or i.Range Like "([一二三四五六七八九]百[一二三四五六七八九零][一二三四五六七八九十])*" Or i.Range Like "([一二三四五六七八九]百[一二三四五六七八九]十[一二三四五六七八九])*" Then
- If i.Range.Sentences.Count = 1 Then t = 1 Else t = 2
- ElseIf i.Range Like "#.*" Or i.Range Like "##.*" Or i.Range Like "###.*" Or i.Range Like "####.*" Then
- If i.Range.Sentences.Count = 1 Then f = 1 Else f = 2
- ElseIf i.Range Like "(#)*" Or i.Range Like "(##)*" Or i.Range Like "(###)*" Or i.Range Like "(####)*" Then
- If i.Range.Sentences.Count = 1 Then v = 1 Else v = 2
- End If
- If s = 1 Or t = 1 Or f = 1 Or v = 1 Then
- If i.Range Like "*[。:;,、!?”…—.:;,!?]" & vbCr Then i.Range.Characters.Last.Previous.Delete
- With i.Range.ParagraphFormat
- If s = 1 Then
- .Style = wdStyleHeading2
- .CharacterUnitFirstLineIndent = 1.74
- i.Range.Font.Color = wdColorRed '红色
- ElseIf t = 1 Then
- .Style = wdStyleHeading3
- .CharacterUnitFirstLineIndent = 1.75
- i.Range.Font.Color = wdColorPink '粉红
- ElseIf f = 1 Then
- .Style = wdStyleHeading4
- .CharacterUnitFirstLineIndent = 1.99
- i.Range.Font.Color = wdColorGreen '绿色
- ElseIf v = 1 Then
- .Style = wdStyleHeading5
- .CharacterUnitFirstLineIndent = 2
- i.Range.Font.Color = wdColorOrange '橙色
- End If
- .SpaceBefore = 0
- .SpaceAfter = 0
- .LineSpacing = LinesToPoints(1.25)
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- .KeepWithNext = False
- .KeepTogether = False
- End With
- ElseIf s = 2 Or t = 2 Or f = 2 Or v = 2 Then
- With i.Range.Sentences(1).Font
- .Name = "黑体"
- .Name = "Times New Roman"
- .Bold = True
- .Color = wdColorBrown '褐色
- End With
- 'add
- If f = 2 Then
- i.Range.Characters.First.Select
- Do While Selection Like "*[0-9]"
- Selection.MoveEnd unit:=wdCharacter, Count:=1
- Loop
- Selection.Font.Name = "Arial"
- Selection.Font.Bold = True
- Selection.Characters.Last.Font.Name = "黑体"
- End If
- End If
- s = 0: t = 0: f = 0: v = 0
- Next
- End Sub
复制代码 |
|