|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 duquancai 于 2017-5-16 01:43 编辑
Sub 例文demo()
' 针对Word所有通用文档!!!(适用于:表格、图片、图形、文本框及艺术字、图文框、域、自动编号)
' 文档变化说明:所有的浮动对象将转为嵌入对象,域将被解除,自动编号将被转为手动编号!!!
算了还是按照你的要求来吧!!!
Sub 四种标题层次4中颜色()
' 文档中有表格,没有图片、图形、域等,请自行清楚段首空格!!!
Dim mt, reg As Object, n&, m&, L&
ostr$ = Replace(ActiveDocument.Content, Chr(7), "")
sr$ = "〇一二三四五六七八九十百千万亿"
r1$ = "^[" & sr & "]+、": r2$ = "^[((]\s*[" & sr & "]+\s*[))]"
r3$ = "^\d+[、..]": r4$ = "^[((]\s*\d+\s*[))]"
Set reg = CreateObject("vbscript.regexp")
reg.Global = True: reg.MultiLine = True
reg.Pattern = "" & r2 & "|" & r1 & "|" & r4 & "|" & r3 & ""
For Each mt In reg.Execute(ostr)
m = mt.FirstIndex: n = mt.Length
With ActiveDocument.Range(m, m + n)
.Expand 4: L = Len(.Text): .Collapse
If .MoveWhile(sr, L) > 0 Then
.Expand 4: .Font.ColorIndex = 6
ElseIf .MoveWhile("((", L) > 0 Then
If .MoveWhile(sr, L) > 0 Then
.Expand 4: .Font.ColorIndex = 5
Else
.Expand 4: .Font.ColorIndex = 11
End If
Else
.Expand 4: .Font.ColorIndex = 2
End If
End With
Next
End Sub
|
|