当使用 range.find 查找粗体文本时,如果整个选择都是粗体,则不会找到!

发布于 2024-07-24 09:51:35 字数 472 浏览 1 评论 0原文

我正在尝试使用 range.find 方法提取粗体文本,除非整个范围实际上是粗体(不太可能发生,它更多的是边缘条件),否则一切都是桃色的。

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 是怎么想的?

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两仪 2024-07-31 09:51:35

这应该找到任何粗体文本:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文