Sub test()
Dim str, reg, match, matchs, x
Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
str = "关键词"
For Each x In ActiveSheet.UsedRange
If InStr(x, str) Then
x.Font.ColorIndex = xlAutomatic
reg.Pattern = str
Set matchs = reg.Execute(x)
For Each match In matchs
x.Characters(Start:=match.firstindex + 1, Length:=match.Length).Font.ColorIndex = 3
Next
End If
Next
End Sub
Sub test()
Dim str, reg, match, matchs, x
Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
str = "关键词"
For Each x In ActiveSheet.UsedRange
If InStr(x, str) Then
x.Font.ColorIndex = xlAutomatic
reg.Pattern = str
Set matchs = reg.Execute(x)
For Each match In matchs
x.Characters(Start:=match.firstindex + 1, Length:=match.Length).Font.ColorIndex = 3
Next
End If
Next
End Sub