|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本人菜鸟一枚,在尝试用word vba中用正则表达式设置金额数字千分位后,文档的字体、段落格式被改变了(此为其中的一个,有几十个文档,批量设置的部分代码基本完工,但同样遇到了的格式问题),怎么保持字体、段落等格式不变啊?请各位大佬指点。附代码如下:
Sub Word金额数字添加千分空()
'By 一泓之沚
’仅对数字+"元"样式有效
Dim regx As Object
Dim docstr, mystr, strpad, n
Application.DisplayAlerts = False
Application.ScreenUpdating = False
n = 0
docstr = ActiveDocument.Content
strpad = ".8888元"
Set regx=CreateObject("vbscript.regexp")
With regx
.MultiLine = True
.Global = True
.Pattern = "((\.\d+[\w\W]+?)*?\d)(?=(\d{3})+((\.\d+)?)元)"
mystr= .Replace(docstr & strpad, "$1 ")
End With
ActiveDocument.Content.Text = Left(mystr, Len(mystr) - Len(strpad) - 1)
ActiveDocument.Save
n = regx.Execute(docstr).Count + n
Set regx = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "金额数字千分位样式设置已累计完成" & n & "处!", vbInformation, "提示"
End Sub
|
|