如在word中有类似以下文本:
只想把数字后的逗号替换为空格,其它保持不变,可以在VBA使用正则表达式。
其它类似的查找和替换只要给.Pattern属性赋不同的值即可。至于正则表达式的构造在不同的编程语言中都是大同小异。
附代码:
Sub replacetxt()
Dim regex As Object
Dim regMatch As Object
Set regex = CreateObject("VBScript.RegExp")
Dim str As String
str = Selection.Text
With regex
.Pattern = "(\d),"
.MultiLine = True
.Global = True
.IgnoreCase = True
str = .Replace(str, "$1 ")
Debug.Print (str)
End With
Selection.Text = str
End Sub
-End-
本文暂时没有评论,来添加一个吧(●'◡'●)