none
Macro to highlight yellow all capitalized words in a contract that not defined in the contract. RRS feed

  • Question

  • As a lawyer, I write contracts that define certain words to have special significance in the contract.   Example:

    This Master Services Agreement ("Agreement") is dated effective as of June 6, 2018 ("Effective Date") and is made by ABC Company ("ABC") and XYZ Company ("XYZ"), who shall collectively be referred to herein as the "Parties."  The Parties, intending to be legally bound, agree as follows:

    ======SAMPLE CONTRACT LANGUAGE START

    1. Services.  XYZ shall provide technology consulting services ("Services") to ABC for the 12-month period commencing on the Effective Date ("Term").  XYZ shall provide the Services to ABC using Professional Standards and shall deliver all Deliverables promptly no later than the delivery dates mutually agreed by the Parties in writing.

    [Contract goes on...]

    ======SAMPLE CONTRACT LANGUAGE END

    I seek to create a macro that would highlight yellow in the above example, the phrase "Professional Standards" and the word "Deliverables" because neither of those capitalized terms is defined in this snippet of the Agreement.  I've attempted this macro several times, but it's so cumbersome that it takes too long to process, say, a 60-page contract.   I need this macro so I can better proof these contracts for finalization to ensure that all capitalized terms used in the Agreement are defined in it somewhere (i.e. all capitalized terms are defined, within quotes, somewhere in the Agreement).  

    This ask is challenging for a few reasons.   First, the macro can't just look at single capitalized words.  For example, "Professional Standards" is two words, and sometimes capitalized phrases are 3 or 4 words long.   Second, the macro needs to ignore certain conditions, like the first capitalized word in every paragraph and every sentence.  Third, the macro needs to ignore certain words that are capitalized by grammar conventions, such as days of the week, months, and certain common proper nouns (e.g., 
    United States").  On this third point, I've loaded an array with a list of certain proper nouns and as a last step, have the macro de-highlight any applicable terms.

    I seek help in creating an computationally EFFICIENT macro.   In my attempts, my macro conceptually did the following:

    (1) Using a Scripting.Dictionary, macro goes through entire contract looking for words and phrases within quotations (i.e., the "defined terms") and saves them into memory using the Scripting Dictionary.

    (2) Highlights in contract, all capitalized words, using simple find/replace routine.

    (3) Then, I cycle through a number of sub-routines, each designed to REMOVE highlighting so that when the steps are complete, all that remains highlighted are the words that are capitalized, but not defined (always with a few exceptions, which I want to minimize).

    (4) Cycle 1: Remove highlighting for certain proper nouns and other capitalized terms that won't be applicable, like "Section," days of the week, names of US States, etc.

    (5) Cycle 2: Remove highlighting for all terms that ARE defined.   Here, I use a find/replace routine to remove highlighting for each defined term or phrase, by looping through each term or phrase in the Scripting.Dictionary and de-highlighting it.

    (6) Cycle 3: Remove highlighting for the first word in each paragraph and sentence. [* I don't have the skills to program this routine efficiently, and I think this step is one of the ones that bogs down the overall execution because I cycle through each sentence in the Agreement, select the first word, and de-highlight it.

    (7) Cycle 4: Remove highlighting from all "Section Headers."  In legal contracts, section headers are usually capitalized, but for this exercise, these section headings should NOT be highlighted.  E.g., "1.  Services. XYZ shall....," "2. Payment Terms.  ABC shall pay all invoices...," "2.1 Invoices, Taxes and Late Payment Terms.  All invoices shall be..." [in the foregoing, capitalized terms "Services," "Payment Terms," and "Invoices, Taxes and Late Payment Terms." should NOT be highlighted.] [*Again, I don't have the programming skills to efficiently perform this routine, and it too bogs down overall execution.]

    Please help!  At his point I'm locked into the above conceptual framework and can't think of alternative ways to more efficiently achieve the desired end result.   Any ideas on how to better go about accomplishing this macro project?

    Wednesday, June 6, 2018 4:19 PM

All replies

  • See the 2nd & 3rd macros in: http://www.msofficeforums.com/word/12090-need-macro-make-list-defined-terms.html#post32031 Together, these macros build a table of all the double-quoted terms in the document, including the pages on which they appear. For your purposes, you'll want to set lCol = 1. This more-or-less achieves what you want with (1), the difference being that it's not stored in memory (and you may find it useful to have a list of such terms in your document anyway).

    You can then use a wildcard Find/Replace to highlight all words beginning with capitals, where:
    Find = <[A-Z][A-Za-z]@>
    Replace = ^&
    and you set the replacement highlight option. This achieves what you want with (2). The macro for (4) & (5) -see below - handles this, too.

    Having done that, you can use the following macro to remove the highlighting from all words in the document that are found in the 'defined terms' table produced by the first macro. If you add your exclusions to that table, they'll be processed, too. This achieves what you want with (4) & (5).

    Sub HiliteUndefined()
    Application.ScreenUpdating = False
    Dim oTbl As Table, i As Long
    Options.DefaultHighlightColorIndex = wdBrightGreen
    With ActiveDocument.Range
      Set oTbl = .Tables(.Tables.Count)
      With .Find
        .ClearFormatting
        .Format = False
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWildcards = True
        .Text = "<[A-Z][A-Za-z]@>"
        With .Replacement
          .ClearFormatting
          .Text = "^&"
          .Highlight = True
        End With
        .Execute Replace:=wdReplaceAll
        With .Replacement
          .ClearFormatting
          .Highlight = False
        End With
      End With
      For i = 2 To oTbl.Rows.Count
        With .Find
          .Text = Split(oTbl.Cell(i, 1).Range.Text, vbCr)(0)
          .Execute Replace:=wdReplaceAll
        End With
      Next
    End With
    Application.ScreenUpdating = True
    End Sub

    What you're asking for (6) is problematic, since an undefined key term of one or more words may in fact start a sentence. That said, the following macro should get you fairly close:

    Sub ClearSentenceHilites()
    Application.ScreenUpdating = False
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Format = True
        .Highlight = True
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = False
        .Text = ""
        .Replacement.Text = ""
        .Execute
      End With
      Do While .Find.Found
        If .Start = .Sentences(1).Start Then
          If .Words.First.Next.HighlightColorIndex = wdNoHighlight Then
            .HighlightColorIndex = wdNoHighlight
          Else
            Do While .Words.Last.Next.HighlightColorIndex <> wdNoHighlight
              .End = .Words.Last.Next.Words.First.End
            Loop
          End If
        Else
          .HighlightColorIndex = wdNoHighlight
        End If
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With
    Application.ScreenUpdating = True
    End Sub

    This macro could actually be called from the one that does the processing for (4) & (5).

    If you've used Heading Styles for your headings, the following macro will remove any highlighting from them. This achieves what you want with (7).

    Sub ClearHeadingHilites()
    Application.ScreenUpdating = False
    Dim i As Long
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Format = True
        .Highlight = True
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWildcards = False
        .Text = ""
        With .Replacement
          .ClearFormatting
          .Text = ""
          .Highlight = False
        End With
        For i = 1 To 9
          .Style = "Heading " & i
          .Execute Replace:=wdReplaceAll
        Next
      End With
    End With
    Application.ScreenUpdating = True
    End Sub

    This macro too could be called from the one that does the processing for (4) & (5), or from the one that does the processing for (6).

    What you'll be left with after the above is a document with various highlighted words for you to check.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, June 7, 2018 12:12 AM