|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
* 杜先生,请看代码中间星号(*)部分的问题,请指教:
- Sub Title2345()
- '更新--杜先生 此法最快!
- Dim mt, reg As Object, n&, m&, L&, ostr$, sr$, r1$, r2$, r3$, r4$, v As Range
- ostr = Replace(ActiveDocument.Content, Chr(7), "")
- sr = "一二三四五六七八九十百零千〇"
- r1 = "^[" & sr & "]+、"
- r2 = "^[((]\s*[" & sr & "]+\s*[))]"
- r3 = "^\d+[、..]"
- r4 = "^[((]\s*\d+\s*[))]"
- Set reg = CreateObject("vbscript.regexp")
- With reg
- .Global = True
- .MultiLine = True
- .Pattern = "" & r2 & "|" & r1 & "|" & r4 & "|" & r3 & ""
- For Each mt In .Execute(ostr)
- m = mt.FirstIndex
- n = mt.Length
- With ActiveDocument.Range(m, m + n)
- If Not .Information(wdWithInTable) Then
- .Expand 4: L = Len(.Text): .Collapse
- If .MoveWhile(sr, L) > 0 Then
- .Expand 4
- .Style = "标题 2"
- .Font.ColorIndex = 6
- ElseIf .MoveWhile("((", L) > 0 Then
- If .MoveWhile(sr, L) > 0 Then
- .Expand 4
- .Style = "标题 3"
- With .Font
- .Name = "楷体"
- .Name = "Times New Roman"
- .ColorIndex = 5
- End With
- Else
- .Expand 4
- .Style = "标题 5"
- With .Font
- .Name = "仿宋"
- .Name = "Times New Roman"
- .ColorIndex = 12
- End With
- End If
- Else
- .Expand 4
- .Style = "标题 4"
- With .Font
- .Name = "仿宋"
- .Name = "Times New Roman"
- .ColorIndex = 11
- End With
- End If
- If .Style <> "正文" Then
- If .Sentences.Count = 1 Then
- If ActiveDocument.Range(m, m + n) Like "*[。:;,、!?…—.:;,!?]?" Then .Characters.Last.Previous.Delete
- '*********************************************************************************************************************************
- '杜先生:上面这行语句,不像 i.Range 那样能删除段落(.Sentences.Count=1)末尾标点符号,不知道怎么办,请 杜先生 指教!
- '如果改成 .Select:Selection 那样,则“一、XX;二、XX;三、XX都能正确设置,但:四、XX不能设置”;而且激活、选定后速度慢一倍多。
- '*********************************************************************************************************************************
- Else
- With .Font
- .Name = "仿宋"
- .Name = "Times New Roman"
- .Bold = False
- .Color = wdColorBlue
- End With
- With .Sentences(1).Font
- .Bold = True
- .Color = wdColorBrown
- End With
- End If
- End If
- With .Font
- .Size = 16
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .SpaceBeforeAuto = False
- .SpaceAfterAuto = False
- .SpaceBefore = 0
- .SpaceAfter = 0
- .LineSpacing = LinesToPoints(1.25)
- .CharacterUnitFirstLineIndent = 2
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- .KeepWithNext = False
- .KeepTogether = False
- End With
- End If
- End With
- Next
- End With
- End Sub
复制代码 |
|