Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 10-30-2016, 12:27 PM
Gilvv Gilvv is offline How to highlight text in a Word document using a word list from another document Windows 7 64bit How to highlight text in a Word document using a word list from another document Office 2010 64bit
Advanced Beginner
How to highlight text in a Word document using a word list from another document
 
Join Date: Oct 2016
Posts: 30
Gilvv is on a distinguished road
Default

Thank you very much, macropod!


You are truly a master!


I do appreciate your beautiful, elegant solution. Thank you for taking the time to address my question!


I applied your code to one of my texts and it works like a charm. However, there is a little problem I’m trying to resolve applying the same idea you suggested (using Comments for the explanatory text): My table of terms is rather large (about 4300 rows) and running the code takes a long time –more than 6 or 7 minutes for a small text (2 pages) that I’m using for testing. The code below, which I used to only highlight the matching terms, took 20 seconds or so for the same text. Would adding the comments add that much time?

Once again, macropod, thank you very much for your help!

PS. Seeing your code really gives me the motivation and inspiration to learn VBA in depth. (Any recommendation for a text or handbook I could use?)

Code:
Sub Finder()
      Dim sCheckDoc As String
      Dim docRef As Document
      Dim docCurrent As Document
      Dim wrdRef As String
      Dim wrdPara As Paragraph
   
      sCheckDoc = "c:\FilePath\Glossary.docx"
      Set docCurrent = Selection.Document
      Set docRef = Documents.Open(sCheckDoc)
      docCurrent.Activate
   
      With Selection.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Replacement.Highlight = True
          .Replacement.Text = "^&"
          .Forward = True
          .Format = True
          .MatchWholeWord = False
          .MatchCase = False
          .MatchWildcards = False
      End With
   
      For Each wrdPara In docRef.Paragraphs
          wrdRef = wrdPara.Range.Text
          wrdRef = Left(wrdRef, Len(wrdRef) - 1)
              If Asc(Left(wrdRef, 1)) > 32 Then
                  With Selection.Find
                  .MatchWholeWord = True
                  .MatchCase = False
                  .MatchSoundsLike = False
                  .Wrap = wdFindContinue
                  .Text = wrdRef
                  .Execute Replace:=wdReplaceAll
      End With
              End If
      Next wrdPara
   
      docRef.Close
      docCurrent.Activate
  End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to highlight text in a Word document using a word list from another document Find and highlight multiple words in MS Word document AtaLoss Word VBA 37 09-22-2021 12:04 PM
How to highlight text in a Word document using a word list from another document Linking one word document to a 'master' word document - even if files are in private drive mb3344 Word 2 08-06-2016 07:10 PM
Adding tables to Created word document whilst other word document open Help rpb925 Word VBA 18 03-30-2016 04:45 PM
How to highlight text in a Word document using a word list from another document Word document with Macros with trusted locatin versus Word document 1997-2003 Cardinal2 Word 1 11-30-2015 07:42 PM
Can Word highlight the same text in the Reviewing Pane as in the main document? wordistheword Word 4 09-09-2013 04:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft