正则表达式替换正文内容

发布于 2024-11-09 03:19:55 字数 298 浏览 4 评论 0原文

我尝试以下方法将当前打开文档中的所有文本内容替换为数字零,但它不起作用

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")

任何人都可以建议一种工作方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2024-11-16 03:19:55

假设您引用了 microsoft vbscript 正则表达式

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

将会起作用,尽管您当然会丢失任何格式。

您还可以使用内置的搜索/替换,它对查找数字/字符的支持有限。录制您自己执行此操作的宏,然后您可以检查代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文