Results 1 to 14 of 14

Thread: Highlight Chinese characters from a list

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Highlight Chinese characters from a list

    Dear all,

    Apologies if this is the wrong place to post.

    I was looking for a code to help me highlight words based on a vocab list. I found these codes work ok running Macro. https://wordribbon.tips.net/T001173_...Word_List.html

    However, it does not work when I tried to search and highlight Chinese characters. Please see attached.

    Could you please help? I am no coder and know nothing about Macro apart from copy and paste the codes.

    Thank you so very much. 谢谢!

    Regards,
    Andrew
    Attached Files Attached Files

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Re: Highlight Chinese characters from a list

    Here are the codes:
    Code:
    Sub CompareWordList()
        Dim sCheckDoc As String
        Dim docRef As Document
        Dim docCurrent As Document
        Dim wrdRef As Object
    
        sCheckDoc = "c:\checklist.doc"
        Set docCurrent = Selection.Document
        Set docRef = Documents.Open(sCheckDoc)
        docCurrent.Activate
    
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Replacement.Font.Bold = True
            .Replacement.Text = "^&"
            .Forward = True
            .Format = True
            .MatchWholeWord = True
            .MatchCase = True
            .MatchWildcards = False
        End With
    
        For Each wrdRef In docRef.Words
            If Asc(Left(wrdRef, 1)) > 32 Then
                With Selection.Find
                    .Wrap = wdFindContinue
                    .Text = wrdRef
                    .Execute Replace:=wdReplaceAll
                End With
            End If
        Next wrdRef
    
        docRef.Close
        docCurrent.Activate
    End Sub
    Last edited by Shaggy Hiker; Jan 18th, 2022 at 12:25 PM. Reason: Added CODE tags.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,753

    Re: Highlight Chinese characters from a list

    That is VBA. This is the VB.Net general forum. Your question should be placed in the Office Development forum. I'll notify a moderator for you...

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,576

    Re: Highlight Chinese characters from a list

    i did a bit of copy and paste, and tested your code, appeared to work correctly to bold, but no highlight

    add one line
    Code:
            .Replacement.Highlight = True
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Re: Highlight Chinese characters from a list

    Thank you westconn1. Did you use the Chinese characters? Thanks!

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Re: Highlight Chinese characters from a list

    Thank you Paul. Much appreciate it.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,576

    Re: Highlight Chinese characters from a list

    i was using your samples, which contained characters that i assumed were chinese
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Re: Highlight Chinese characters from a list

    That's interesting... I'm using word MS 365 on a MacBook. Do you think this will be the problem?
    Thank you again.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,753

    Re: Highlight Chinese characters from a list

    Quote Originally Posted by MandarinMrZhang View Post
    That's interesting... I'm using word MS 365 on a MacBook. Do you think this will be the problem?
    Thank you again.
    If you're not sure, try it and see the results on your MacBook...

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Re: Highlight Chinese characters from a list

    Thank you .paul.
    It does not work on my MacBook with the Chinese characters ; (
    If I search English words, that words perfectly.
    I'll try on a PC Monday.
    Thanks again.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,576

    Re: Highlight Chinese characters from a list

    i was testing on a real pc, win10 office 2010

    quite a lot of VBA does not work correctly on mac
    Name:  clipic.jpg
Views: 40
Size:  27.5 KB
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Re: Highlight Chinese characters from a list

    Thank you very much. This is really helpful.
    Cheers!

  13. #13

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    8

    Re: Highlight Chinese characters from a list

    One last question, I cannot find the button to mark the post as resolved 😅

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,576

    Re: Highlight Chinese characters from a list

    at the top of the original post under thread tools
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width