How to Use VBA to Find Missing Contract Clauses in Word Documents
Question details
The user needs a VBA macro to compare a legal contract against a source document of required clauses and identify any missing text strings.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Automating a final legal-content check to ensure all required clauses are present in a drafted contract.
- Observed behavior
- The macro needs to read the source document, search the contract using Word's Find method, and display any unmatched missing clauses in a message box or report.
Ensure both your source document containing the required clauses and the target contract document are saved on your computer. Make sure you have enabled the Developer tab in Word to access the VBA Editor.
Create a VBA Macro to Compare Clauses
Use Word's VBA editor to write a script that reads clauses from a source document and searches for them in the active contract document.
Store each required clause as a separate paragraph in your source document. The VBA script will loop through these paragraphs and use the Find method to verify their presence in the contract.
Because formatting, punctuation, and wording variations can easily cause false mismatches, you should normalize the text by ignoring extra whitespace and line breaks. This macro is best used as an assistive check rather than a definitive legal review.
Open your contract document in Word and press Alt + F11 to launch the Visual Basic for Applications (VBA) Editor.
Go to Insert > Module in the top menu to create a blank script module where you will write your VBA code.
Write a macro that uses Documents.Open to open the source document. Loop through each paragraph (clause) in the source document and assign its text to a variable.
For each clause, activate the contract document and use the Selection.Find method. If the Find execution returns false, append the missing clause text to a string variable.
At the end of the loop, use the MsgBox function to display the collected string of missing clauses. If the text is very long, use Documents.Add to create a new report document and insert the text there.

Compare and Review Contracts Efficiently with WPS Office
WPS Writer offers advanced built-in document comparison and review features, making it easy to spot missing clauses or differences between two contract versions without writing complex VBA code.
- 1. Open WPS Writer: Launch WPS Writer and navigate to the Review tab on the top ribbon.
- 2. Access the Compare Tool: Click on the Compare button and select 'Compare...' from the drop-down menu.
- 3. Select Your Documents: In the dialog box, choose your original source document (containing the required clauses) and the current contract document.
- 4. Generate the Comparison Report: Click OK to generate a new document that clearly highlights all missing clauses, additions, and formatting modifications with track changes.

Frequently Asked Questions
Why does the VBA macro say a clause is missing when it is actually in the contract?
This usually happens due to formatting inconsistencies, extra spaces, hidden characters, or different punctuation. Normalizing the text (such as removing extra spaces and ignoring case) in your VBA code can reduce these false positives.
Can I use the built-in Compare feature instead of VBA for checking contracts?
Yes, Microsoft Word and WPS Writer both have a built-in 'Compare Documents' feature under the Review tab. This highlights all structural and text differences between two document versions automatically without requiring any code.
How do I output the missing clauses to a new document instead of a message box?
Instead of passing your results to the MsgBox function, your VBA script can create a new document using Documents.Add. You can then insert the collected missing clause strings into this new document using the Selection.TypeText method.
Is it safe to rely completely on VBA macros for legal contract reviews?
No, VBA macros should only be used as a preliminary assistive check. Due to the nuances of legal language, formatting glitches, and potential false positives/negatives, a manual review by a qualified legal professional is always necessary.




