How can I make this Asian font highlighting macro recognize between-word characters?

112 views Asked by At

For most of the documents I work with, I need to highlight instances of Asian font (such as SimSun, MS Mincho).

I put together the the code below - it works well but it doesn't highlight Asian font characters within non-Asian words (such as the apostrophe in "it's").

Sub HighlightAsian2019()
Dim aWord
    For Each aWord In ActiveDocument.Words
        If aWord.Font.Name = "SimSun" Then
           aWord.FormattedText.HighlightColorIndex = wdTurquoise
        End If
    Next aWord
    For Each aWord In ActiveDocument.Words
        If aWord.Font.Name = "MS Mincho" Then
           aWord.FormattedText.HighlightColorIndex = wdTurquoise
        End If
    Next aWord
End Sub

Can anyone help me improve the code so that ALL instances of SimSun and MS Mincho in the text are highlighted?

Any help will be greatly appreciated!

2

There are 2 answers

0
Mikku On BEST ANSWER

Use this Loop:

Sub HighlightAsian2019()

With ActiveDocument.Range

    For i = 1 To .Characters.Count
        If .Characters(i).Font.Name = "SimSun" Then
            .Characters(i).FormattedText.HighlightColorIndex = wdTurquoise
        End If
    Next

End With

End Sub

You can use the .Characters property of Range to access the alphabets. Add another If condition for other fonts to check

0
Ahmed AU On

Since I don't have that particular font, I tested with other fonts, may try with modifying the font names.

Sub test()
Dim Rng As Range
Set Rng = ThisDocument.Content
With Rng.Find
.ClearFormatting
.Text = ""
.Font.Name = "Kruti Dev 040 Wide"
    Do While .Execute
    Rng.FormattedText.HighlightColorIndex = wdTurquoise
    Loop
End With
End Sub