尝试删除包含黄色突出显示文本的行

发布于 2024-12-10 04:45:11 字数 409 浏览 0 评论 0原文

我正在审阅一份带有黄色突出显示文本的文档。我想要一个宏来遍历并删除突出显示的行。到目前为止,这就是我所拥有的:

Sub hilight()
'
' hilight Macro
' removes lines in yellow hi-lighter

Dim p As Paragraph

For Each p In ActiveDocument.Paragraphs
    Dim holder As String
    If p.Range.Text = highlighted_text Then
        p.Range.Text = holder
    End If
Next p

End Sub

我需要知道如何给出突出显示的文本属性,以便我可以替换 highlighted_text

i have a document that i'm reviewing with yellow highlighted text. i want a macro to go through and remove the lines that are highlighted. so far this is what i have:

Sub hilight()
'
' hilight Macro
' removes lines in yellow hi-lighter

Dim p As Paragraph

For Each p In ActiveDocument.Paragraphs
    Dim holder As String
    If p.Range.Text = highlighted_text Then
        p.Range.Text = holder
    End If
Next p

End Sub

i need to know how highlighted text property is given so i can replace highlighted_text

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

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

发布评论

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

评论(1

┼── 2024-12-17 04:45:11

这是一个解决方案。请注意,它仅替换整个段落以黄色突出显示的段落,而不仅仅是其中的一部分。有几件事值得指出:

  • 替换段落也会删除尾随换行符,因此我将其包含在占位符文本中
  • 由于添加了换行符,如果您不向后循环段落,它会被删除。将是一个无限循环(因此步骤-1)将
  • 循环外的所有变量调暗
Sub ReplaceYellowParagrahps()

Dim p As Paragraph
Dim i As Long, count As Long
Dim placeholderText As String
placeholderText = "holder" & vblf

count = ActiveDocument.Paragraphs.count

For i = count To 1 Step -1
    With ActiveDocument.Paragraphs(i).Range
        If .HighlightColorIndex = wdYellow Then
            .Text = placeholderText
        End If
    End With
Next

End Sub

Here is a solution. Note that it only replaces paragraphs in which the entire paragraph is yellow highlighted, not just part of it. There are a few things worth pointing out:

  • Replacing a paragraph will also take out the trailing line break, so I include it in the placeholder text
  • Since a line break is being added, if you don't loop through the paragraphs backwards, it'll be an infinite loop (thus the step -1)
  • Dim all variables outside of a loop
Sub ReplaceYellowParagrahps()

Dim p As Paragraph
Dim i As Long, count As Long
Dim placeholderText As String
placeholderText = "holder" & vblf

count = ActiveDocument.Paragraphs.count

For i = count To 1 Step -1
    With ActiveDocument.Paragraphs(i).Range
        If .HighlightColorIndex = wdYellow Then
            .Text = placeholderText
        End If
    End With
Next

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