如何在活動檔案中找到突出顯示文本的所有實體并使用標記洗掉突出顯示格式?
我在https://learn.microsoft.com/en-us/office/vba/api/word.find.highlight中找到了一個宏。但我希望它洗掉帶有標記的突出顯示格式。我試圖添加“ActiveDocument.TrackRevisions = True”以打開跟蹤更改但徒勞無功。
Sub A()
Dim rngTemp As Range
Set rngTemp = ActiveDocument.Range(Start:=0, End:=0)
With rngTemp.Find
.ClearFormatting
.Highlight = True
With .Replacement
.ClearFormatting
.Highlight = False
End With
.Execute Replace:=wdReplaceAll, Forward:=True, FindText:="", _
ReplaceWith:="", Format:=True
End With
End Sub
然后我嘗試錄制一個宏并編輯如下:
Sub Macro1()
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
With Selection.Find
.Text = ""
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Options.DefaultHighlightColorIndex = wdNoHighlight
Selection.Range.HighlightColorIndex = wdNoHighlight
Selection.Find.Execute
End Sub
第二個只能通過標記將突出顯示的文本更改為不突出顯示。這很不方便,因為我至少有 200 個突出顯示的文本來決定是否應該在檔案中更正它們。如何編輯它以自動選擇所有突出顯示的文本,然后使用標記洗掉它們的突出顯示?
uj5u.com熱心網友回復:
Sub FindRemoveHighlighting()
Dim findRange As Range: Set findRange = ActiveDocument.Content
ActiveDocument.TrackRevisions = True
With findRange
With .Find
.Highlight = True
.Text = ""
.Format = True
End With
Do While .Find.Execute() = True
.HighlightColorIndex = wdNoHighlight
.Collapse wdCollapseEnd
Loop
End With
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518033.html
標籤:vbams-word
下一篇:單元格值超過4位小數時的錯誤訊息
