如何找到 MS Word 文档中突出显示的文本块的数量
我正在 MS Word 中编写一个宏,它应该找到文档中所有突出显示的文本并对每个文本执行一些操作。我正在计划一个循环来执行搜索和操作部分,并且这部分代码没有问题。
但我不知道如何找到我需要多少次迭代。有没有办法确定VBA中突出显示的数量?
非常感谢。
I am writing a macro in MS Word which should find all highlighted text in a document and perform some action on each. I am planning a loop to do the search and manipulation part and have no problem with this portion of the code.
But I don't know how to find how many iterations I'm going to need. Is there a way to determine the number of highlights in VBA?
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需预先计算匹配数。您可以循环执行搜索,一旦没有更多匹配项,搜索就会停止。
确保将搜索应用到文档的正确部分。我使用了 ActiveDocument.Range,但任何
Range
对象都可以。也许更具体的东西更适合您的情况。另外,检查 Find 对象的许多其他属性并将它们设置为合理的值,这比使用默认值要好(没有人能记住所有选项的所有默认值,加上 Find 对象可能已通过某些早期搜索设置)。
There's no need to calculate the number of matches up-front. You can execute the search in a loop and it will stop once there are no more matches.
Make sure you apply the search to the right part of the document.I used
ActiveDocument.Range
, but anyRange
object will do. Maybe something more specific is better for your case.Also, check out the many other properties of the
Find
object and set them to sensible values, this is better than going with the defaults (nobody can remember all defaults for all options, plus theFind
object might already be set up by some earlier search).