我有一个文档,我正在审查黄色突出显示的文本。我想要一个宏通过并删除突出显示的行。到目前为止,我得到的是:
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
这是一个解决方案。注意,它只替换整个以黄色突出显示的段落,而不仅仅是其中的一部分。有几件事值得指出:
- 替换段落也会去掉尾随的换行符,所以我把它包含在占位符文本
- 由于添加了换行符,如果你不向后循环段落,它将是一个无限循环(因此步骤-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