仅查找样式为“标题 1"的文本(Range.Find to match style) [英] Find text only of style "Heading 1" (Range.Find to match style)
本文介绍了仅查找样式为“标题 1"的文本(Range.Find to match style)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在我的文档中找到一些只出现在标题 1"样式中的文本.到目前为止,无济于事.
I am trying to find some text in my document that only appears in "Heading 1" styles. So far, no avail.
示例代码:
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.
修正了拼写错误的if"语句
fixed the mispelt 'if' statement
推荐答案
我觉得你的代码很不错.我最好的猜测是标题 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:
Dim blnFound As Boolean
With ThisDocument.Range.Find
.Text = "The Heading"
.Style = "Heading 1"
Do
blnFound = .Execute
If blnFound Then
Debug.Print "Found"
Else
Exit Do
End If
Loop
End With
我希望这会有所帮助.
这篇关于仅查找样式为“标题 1"的文本(Range.Find to match style)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文