本文介绍了当使用 range.find 查找粗体文本时,它不会找到整个选择是否为粗体!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 range.find 方法提取粗体文本,除非整个范围实际上都是粗体(不太可能发生,这更像是一种边缘条件),否则一切都是桃色的.
I'm trying to extract bold text using the range.find method and all is peachy except if the entire range is actually bold (not likely to happen much, it's more of an edge condition).
With rngFindRange.Find
.ClearFormatting
.Font.Bold = True
Do
.Execute
If Not .Found Then
Exit Do
End If
'do something with found text'
Set rngFindRange = ActiveDocument.Range(rngFindRange.End + 1, Selection.End)
Loop
以上匹配开头或结尾处的粗体文本,甚至两者都匹配,但当整个范围为粗体时则不匹配.我想我可能必须在搜索范围之前测试 range.font.bold = true.stackoverflow 是怎么想的?
The above matches bold text right at the start or right at the end, even both but not when the entire range is bold. I think I might have to test the range.font.bold = true before searching through the range. What does stackoverflow think?
推荐答案
这应该可以找到任何粗体文本:
This should find any bold text:
Sub SearchBoldText()
Dim rng As Range
Set rng = ThisDocument.Range(0, 0)
With rng.Find
.ClearFormatting
.Format = True
.Font.Bold = True
While .Execute
rng.Select
rng.Collapse direction:=wdCollapseEnd
Wend
End With
Set rng = Nothing
End Sub
这篇关于当使用 range.find 查找粗体文本时,它不会找到整个选择是否为粗体!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!