我试图在我的文档中找到一些只出现在“标题 1”样式中的文本。到目前为止,无济于事。
示例代码:
With ThisDocument.Range.Find
.Text = "The Heading"
.Style = "Heading 1" 'Does not work
.Execute
If .Found Then Debug.Print "Found"
End With
请注意,它一直停在目录处。
编辑:修复了拼写错误的“if”语句
最佳答案
你的代码对我来说看起来不错。我最好的猜测是“标题 1”样式存在于您的目录中?
下面的代码应该继续查找,找到所有出现的:
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
我希望这有帮助。
关于vba - 仅查找样式为 "Heading 1"的文本(Range.Find 以匹配样式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9286927/