Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 08-19-2021, 01:31 AM
gmayor's Avatar
gmayor gmayor is offline Highlight words in a table that does not exist in current document Windows 10 Highlight words in a table that does not exist in current document Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

As I said, the difficulty is in establishing in the document what are the abbreviations, which, as far as VBA is concerned, are just random text strings. I can see no consistent way to isolate the abbreviations in the document. They are not even all surrounded by brackets which could have been helpful.

The macro checks each of your listed abbreviations in the table against the document and highlights them. This would then allow you to look through the document to establish which items are not highlighted and therefore missing from the table.

If you then add those items to the table and re-run the macro you will get all the abbreviations highlighted in the document.

Then it would be possible to interrogate the document for the highlighted items and highlight the items in the table that were found in the document. e.g.
Code:
Sub Macro2()
Const sAbbrDoc As String = "C:\Path\Abbreviations.docx"    'the path of the abbreviations table document
Dim oDoc As Document, oAbbr As Document
Dim oRng As Range
Dim i As Long
    Options.DefaultHighlightColorIndex = wdYellow
    Set oDoc = ActiveDocument
    Set oAbbr = Documents.Open(sAbbrDoc)
    Set oRng = oDoc.Range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Highlight = True
        .MatchWildcards = False
        Do While .Execute
            SrcAndRplInStory oAbbr.Tables(1).Range, oRng.Text, "^&", False, False, False
            oRng.Collapse 0
        Loop
    End With
lbl_Exit:
    Set oDoc = Nothing
    Set oAbbr = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
word vba, word vba code, word vba highlight text



Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlight words in a table that does not exist in current document Find and highlight multiple words in MS Word document AtaLoss Word VBA 37 09-22-2021 12:04 PM
How to redact words listed in one document from the current document AlanofBayCourt Word VBA 0 10-31-2019 03:00 AM
Find and highlight multiple words in MS Word document qkjack Word VBA 7 02-21-2018 07:09 PM
Highlight words in a table that does not exist in current document Using VBA to Compare and Highlight words in a Word Table's Row/Cell KeithLee22 Word VBA 2 11-11-2015 03:37 PM
Find and highlight multiple words in a document flatop Word VBA 3 04-16-2014 10:29 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:26 AM.


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