我有下面的VBA代码,用于在Word文档中查找突出显示和带下划线的文本并对其进行编辑(即,将其替换为“ x”并以黑色突出显示)。
我只希望识别和删除仅以绿松石色(或选择的特定颜色)突出显示的文本,而保留以其他颜色突出显示的文本。
我试图以多种方式更改代码,但无济于事。
Sub Redact()
' Redact Macro
' Macro to redact underlined text
' If redacted, text will be replaced by x's, coloured black and highlighted black
Dim OldText, OldLastChar, NewLastChar, NewText, ReplaceChar As String
Dim RedactForm As Integer
Dim flag As Boolean
Application.ScreenUpdating = False
ReplaceChar = "x"
flag = True
While flag = True
' Find next selection
Selection.Find.ClearFormatting
Selection.Find.Font.Underline = wdUnderlineSingle
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Font.Underline = False Then
flag = False
End If
' Create replacement string
' If last character is a carriage return (unicode 13), then keep that carriage return
OldText = Selection.Text
OldLastChar = Right(OldText, 1)
NewLastChar = ReplaceChar
If OldLastChar Like "[?*#]" Then NewLastChar = String(1, 13)
NewText = String(Len(OldText) - 1, ReplaceChar) & NewLastChar
' Replace text, black block
Selection.Text = NewText
Selection.Font.ColorIndex = wdBlack
Selection.Font.Underline = False
Selection.Range.HighlightColorIndex = wdBlack
Wend
Application.ScreenUpdating = True
End Sub
我有下面的VBA代码,用于在Word文档中查找突出显示和带下划线的文本,并对其进行编辑(即,将其替换为“ x”并以黑色突出显示)。我想识别并编辑...
为了识别突出显示颜色所需的是属性Range.HighlightColorIndex
。