Regular expression replace body content

时光毁灭记忆、已成空白 提交于 2019-12-24 09:39:09

问题


I tried the following to replace all the text content in the current open document with numeric zero, but it doesn't work

Set objWdDoc = Word.Application.ActiveDocument

Set objWdRange = objWdDoc.Content

Dim re As New RegExp

re.Global = True
re.Pattern = "[a-z]"
re.IgnoreCase = True
objWdRange = re.Replace(objWdRange, "0")

Can anyone suggest a working method?


回答1:


Assuming you have referenced microsoft vbscript regular expressions

objWdRange.Text = re.Replace(objWdRange, "0")

Will work, although you will of course lose any formatting.

You can also use the built-in search/replace which has limited support to find digits/characters. Record a macro of yourself doing this and you can examine the code.



来源:https://stackoverflow.com/questions/6095740/regular-expression-replace-body-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!