Results 1 to 13 of 13
  1. #1
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Highlight word based on workbook entries (Word 200

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    Dear All,

    I found the macro that highlight misspelled words by Bill Coan at
    http://word.mvps.org/FAQs/MacrosVBA/...pellErrors.htm

    I also found Batch Replacer plug-in from ReplSoft website that replaces a list of words based on the entries in a worksheet list.

    I would like to extend Bill's macro and be able to do the hightlight function of Batch Replacer without closing/leaving my edited document, ie. reading column A of workbook "HighlightList.xls" and highlight all the words that appear in the workbook, in my current document.

    Could anybody kindly assist?

    Thank you in advance.

    Rid

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlight word based on workbook entries (Word

    Just to be sure I'm understanding your question, you want a macro that looks at a currently open Excel worksheet named "HighlightWords.xls" and then highlights any occurrence of those words in the currently active Word document?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Highlight word based on workbook entries (Word 200

    See the attached code. Change the path of the workbook, and the name of the worksheet in the first lines of the procedure.
    Attached Files Attached Files

  4. #4
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlight word based on workbook entries (Word

    Spot on.

    Hans has kindly provided some codes. I am testing them out now.

    Thank you all.

  5. #5
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlight word based on workbook entries (Word

    It works wonder Hans. Thank you so much.

    Asking for your kindness further, how do I go about in modifying the codes so that:
    1. Search all the texts in the current Word document based on the list of words in column A of Sheet 1
    2. Replace the matching word in the Word document with corresponding cell B value (ie. if there is a text that matches cell A1 value, replace the text with cell B1 value), and highlight the replaced words.

    Thank you again in advance. Really appreaciate all the helps.

    Rid

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Highlight word based on workbook entries (Word

    Below the line

    .Text = objWS.Cells(lngRow, 1).Value

    insert this:

    .Replacement.Text = objWS.Cells(lngRow, 2).Value

  7. #7
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlight word based on workbook entries (Word

    Maybe I am asking too much, but is it possible to maintain the original "case" (uppercase, lowercase, title case, etc) of the word without inserting all the possible combination in the worksheet? For example, with one single entry of word "abc" in A1 and "def" in B1, all the occurances of "abc", "ABC", "Abc" are replaced with "def", "DEF", "Def", respectively.

    Thank you.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Highlight word based on workbook entries (Word

    Try changing

    .MatchCase = False

    to

    .MatchCase = True

  9. #9
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlight word based on workbook entries (Word

    By changing the .Matchcase from False to True, those matching words but not matching case are not replaced anymore. But is it possible to have the best of both world? With single entry of "abc" in A1 and "def" in B1, all "ABC", "abc", "Abc" are replaced with "DEF", "def", "Def" respectively. In order words, I do not want to enter additional "ABC" in A2, "DEF" in B2; "Abc" in A3, "Def" in B3, and so on.

    Cheers
    Rid

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Highlight word based on workbook entries (Word

    You can store the lower case words in the worksheet, and add extra lines in the code to handle the variations, using UCase and StrConv. Look up those functions in the online help.

  11. #11
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Highlight word based on workbook entries (Word

    Thanks for the suggestion Hans.

    It is a bit too much for a newbie like me, but will continue trying. For now, I will only use the multiple entries in the worksheet.

    Thank you again,

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Highlight word based on workbook entries (Word

    I wasn't thinking very clearly earlier on. If you set .MatchCase to False, Word should automatically do what you want, it is the default setting.

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Highlight word based on workbook entries (Word

    If you are ready for further adventures with Find and Replace, you could explore wildcard searching. This will let you "correct" all variant forms to one correct form. The thread surrounding <post#=457157>post 457157</post#> has more discussion.

    Actually, upon further review, I'm not sure you want that feature. Hans probably has the simpler and better answer for your request.

Posting Permissions

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