我正在嘗試撰寫 vba 代碼來更改特定單詞的背景顏色,但沒有運氣。我有代碼可以改變背景顏色,但在我要求特定單詞時不會。我有 SQL 代碼,我試圖讓查詢中的所有欄位都以亮綠色突出顯示,所以我的計劃是只輸入欄位名稱并將這些術語以亮綠色突出顯示。目前,如果我取出 if 陳述句,第一行將以亮綠色突出顯示。我有超過3200字要讀。
Dim oSentence As Variant
Dim strSentence As String
strSentence = "Package_Policy_TA"
For Each oSentence In ActiveDocument.Sentences
Debug.Print oSentence
If oSentence = strSentence Then
Stop
oSentence.Font.Shading.BackgroundPatternColorIndex = wdBrightGreen
End If
Next oSentence
uj5u.com熱心網友回復:
例如:
Sub HiliteWords()
Application.ScreenUpdating = False
Dim ArrFnd As Variant, i As Long
'Array of Find expressions
ArrFnd = Array("policy_Id", "policy_payer_option", "rpt_coverage", "coverage_id")
With ActiveDocument
For i = 0 To UBound(ArrFnd)
With .Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindStop
.MatchCase = True
.MatchWholeWord = True
.Text = ArrFnd(i)
.Replacement.Text = ""
End With
Do While .Find.Execute
.Font.Shading.BackgroundPatternColorIndex = wdBrightGreen
.Collapse wdCollapseEnd
Loop
End With
Next
End With
Application.ScreenUpdating = True
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/484145.html