仅查找样式“标题 1”的文本(范围.查找以匹配风格)
我试图在文档中找到一些仅以“标题 1”样式出现的文本。到目前为止,没有任何效果。
示例代码:
With ThisDocument.Range.Find
.Text = "The Heading"
.Style = "Heading 1" 'Does not work
.Execute
If .Found Then Debug.Print "Found"
End With
只是一个注释,它一直停在目录处。
编辑:修复了拼写错误的“if”语句
I am trying to find some text in my document that only appears in "Heading 1" styles. So far, no avail.
Sample Code:
With ThisDocument.Range.Find
.Text = "The Heading"
.Style = "Heading 1" 'Does not work
.Execute
If .Found Then Debug.Print "Found"
End With
Just a note, it keeps stopping at the table of contents.
Edit: fixed the mispelt 'if' statement
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的代码对我来说看起来不错。我最好的猜测是您的目录中存在“标题 1”样式?
下面的代码应该继续查找,查找所有出现的情况:
我希望这会有所帮助。
Your code looks good to me. My best guess is that the 'Heading 1' style exists in your table of contents?
The code below should continue the find, finding all occurrences:
I hope this helps.
我认为它不起作用的原因是您必须设置
标志,并且您可能必须通过 .Styles 方法指定样式:
The reason I think it is not working is because you have to set the
flag, and you may have to specify the style via the .Styles method:
我在谷歌上发现了这个问题,问题中的代码对我不起作用。我进行了以下更改来修复它:
Selection.Find.Style = "Heading 1"
更改为一个对象。.Execute
而不是.Found
获取搜索的布尔结果,我希望这对其他一些 Google 员工有所帮助。
I found this question on Google and the code in the question did not work for me. I have made the following changes to fix it:
Selection.Find.Style = "Heading 1"
to an object..Execute
rather than.Found
I hope this helps some other Googlers.