|
楼主 |
发表于 2017-3-19 15:26
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 weiyingde 于 2017-3-19 15:38 编辑
这是duquancai 给我的代码,很好,但我红字的本部分不懂,请解释一下。
Sub W_移形换位()
Dim reg As Object, mt, mh, oDOC As Document
Set oDOC = ActiveDocument
With oDOC.Content.Find
.Execute "([\((])^32{1,}", , , 1, , , , , , "\1", 2
.Execute "^32{1,}([\))])", , , 1, , , , , , "\1", 2
.Execute "^32{1,}", , , 1, , , , , , "^32", 2
End With
Set reg = CreateObject("vbscript.regexp")
reg.Global = True: reg.Pattern = "[\((][^)\)]+[\))]"
For Each mt In reg.Execute(oDOC.Content)
m = mt.FirstIndex: n = mt.Length
With oDOC.Range(m, m + n)
reg.Pattern = " ": t = reg.Execute(.Text).Count + 1
.Start = .Start - t
.Find.Execute "([一-﨩]{" & t & "})([\((])(*)([\))])", , , 1, , , , , , "\3\2\1\4", 1
reg.Pattern = "[\((][^)\)]+[\))]"
For Each mh In reg.Execute(.Text)
f = mh.FirstIndex: l = mh.Length
With oDOC.Range(.Start + f, .Start + f + l)
.Start = .Start + 1: .End = .End - 1
.Font.Color = RGB(255, 255, 255)
End With
Next
End With
Next
End Sub
代码如下
|
|