[英]How can I change the font color to all the text boxes with the same object name in an entire workbook to red?
[英]Find all instances of yellow text and change font color to red
我需要一個vba宏來搜索MS Word 2007文檔中字體顏色為黃色的所有文本並將其更改為紅色。 打印輸出中不會顯示黃色。 手動選擇和更改將花費我幾個小時。
繼stakx的Word 97解決方案之后,以下是Word 2010中的工作原理:
您可以按如下方式確定原始顏色:
實際上有一個非編程解決方案。 我在Word 97中嘗試過,所以我假設Word 2007仍然允許這樣:
(?)
。 \\1
。 可能實際上不需要步驟2,3和5(輸入搜索和替換正則表達式)。
如果你肯定需要VBA代碼,你應該能夠將上述步驟記錄為宏,然后查看生成的代碼。
Sub ChangeColorWithReplace()
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorYellow
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = wdColorRed
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
另外,這是另一種方法。 它並不是非常快,但它比手動操作更快:
Sub ChangeFontColorByCharacter()
Application.ScreenUpdating = False
Dim d As Document: Set d = ActiveDocument
For i = 1 To d.Characters.Count
If d.Characters(i).Font.TextColor.RGB = RGB(255, 255, 0) Then
d.Characters(i).Font.TextColor.RGB = RGB(255, 0, 0)
DoEvents
End If
Next
Application.ScreenUpdating = True
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.