An implementation of Visual Basic that is built into Microsoft products.
Hi @joe lewis ,
Thanks for reaching out.
Word can search for a single Unicode character using ^u, but it does not support searching for a range of Unicode values in one expression, such as 0591-05AE. Also, ^u uses decimal values, not hexadecimal values, so U+0591 would be searched as ^u1425, not ^u0591.
Word's wildcard engine also does not support Unicode character classes or ranges in the same way that regular expression engines do, so this is not something that can be done with one wildcard Find/Replace pattern.
The suitable way to handle this is with a small VBA macro. The macro below first colors the Hebrew combining marks green, then colors the cantillation marks red afterward. The cantillation range is included in the earlier green pass and then recolored red in the second pass, so the final color for those marks will be red.
I would suggest testing this on a copy of the document first. The code snippets below are provided as reference, so please adjust the ranges, colors, or target document areas as needed for your specific document:
Option Explicit
Sub ColorHebrewDiacriticsAndCantillation()
Application.ScreenUpdating = False
' Hebrew combining marks: accents, points, dots, etc.
ApplyColorToCodeRange &H591, &H5BD, wdColorGreen
ApplyColorToCodeRange &H5BF, &H5BF, wdColorGreen
ApplyColorToCodeRange &H5C1, &H5C2, wdColorGreen
ApplyColorToCodeRange &H5C4, &H5C5, wdColorGreen
ApplyColorToCodeRange &H5C7, &H5C7, wdColorGreen
' Hebrew cantillation marks U+0591 through U+05AE.
ApplyColorToCodeRange &H591, &H5AE, wdColorRed
Application.ScreenUpdating = True
End Sub
Private Sub ApplyColorToCodeRange(ByVal firstCode As Long, _
ByVal lastCode As Long, _
ByVal markColor As WdColor)
Dim story As Range
Dim currentStory As Range
Dim codePoint As Long
For Each story In ActiveDocument.StoryRanges
Set currentStory = story
Do While Not currentStory Is Nothing
For codePoint = firstCode To lastCode
ApplyColorToOneCharacter currentStory, ChrW$(codePoint), markColor
Next codePoint
Set currentStory = currentStory.NextStoryRange
Loop
Next story
End Sub
Private Sub ApplyColorToOneCharacter(ByVal storyRange As Range, _
ByVal searchChar As String, _
ByVal markColor As WdColor)
Dim searchRange As Range
Set searchRange = storyRange.Duplicate
With searchRange.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = searchChar
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Replacement.Font.Color = markColor
.Execute Replace:=wdReplaceAll
End With
End Sub
For this approach, leave wildcards off. The macro is not using Word wildcard syntax; it is simply going through each Unicode character in the range and applying the requested font color. Because it runs a separate find operation for each character in the range, it may take some time on very large documents.
One small note: U+0591 through U+05AE is decimal 1425 through 1454. If you also need to include U+05AF, you can change this line:
ApplyColorToCodeRange &H591, &H5AE, wdColorRed
to this:
ApplyColorToCodeRange &H591, &H5AF, wdColorRed
Hope this helps! If my explanation and the information I provided were helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.