chingching831
New Member
- Joined
- Jun 2, 2022
- Messages
- 35
- Office Version
- 2019
- Platform
- Windows
Hi all,
I am using the below VBA Code to highlight non-English characters. I have quite a lot of text to highlight, and I want them to be highlighted in different colours. Thus, it's a bit time consuming to use the below code. How can I modify it so that I can highlight a number of text in one go with different colours based on the RGB Code?
e.g.
c1 = RGB(255, 0, 0) 'red
c2 = RGB(255, 204, 0) 'yellow
c3 = RGB(0, 0, 255) 'blue
highlight text in red: "蜘蛛侠"
highlight text in yellow: "纵横宇宙"
highlight text in blue: "动画"
Thanks,
SC
I am using the below VBA Code to highlight non-English characters. I have quite a lot of text to highlight, and I want them to be highlighted in different colours. Thus, it's a bit time consuming to use the below code. How can I modify it so that I can highlight a number of text in one go with different colours based on the RGB Code?
e.g.
c1 = RGB(255, 0, 0) 'red
c2 = RGB(255, 204, 0) 'yellow
c3 = RGB(0, 0, 255) 'blue
highlight text in red: "蜘蛛侠"
highlight text in yellow: "纵横宇宙"
highlight text in blue: "动画"
VBA Code:
Sub HighlightStrings_CaseInsensitive_AllowForeignText_NotExactText()
Dim xHStr As String, xStrTmp As String
Dim xHStrLen As Long, xCount As Long, i As Long
Dim xCell As Range
Dim xArr
On Error Resume Next
xHStr = Application.InputBox("What are the words to highlight:", "Word Highlighter")
If TypeName(xHStr) <> "String" Then Exit Sub
Application.ScreenUpdating = Fals5
For Each xCell In Selection
Dim varWord As Variant
For Each varWord In Split(xHStr, Space$(1))
xHStrLen = Len(varWord)
xArr = Split(LCase(xCell.Value), LCase(varWord))
xCount = UBound(xArr)
If xCount > 0 Then
xStrTmp = ""
For i = 0 To xCount - 1
xStrTmp = xStrTmp & xArr(i)
xCell.Characters(Len(xStrTmp) + 1, xHStrLen).Font.ColorIndex = 3
xCell.Characters(Len(xStrTmp) + 1, xHStrLen).Font.Bold = True
xStrTmp = xStrTmp & varWord
Next
End If
Next varWord
Next xCell
Application.ScreenUpdating = True
End Sub
Thanks,
SC