VBA & Macro Problems

Compare Words in Two Word Documents with VBA

Steven ParkerSteven Parker Nov 25, 2026 868 views

Question details

Compare a manuscript against a separate word-list document and produce a list of entries that are absent from the manuscript.

Compare Words in Two Word Documents with VBA
Product
Microsoft Word VBA
Device & OS
not provided
Scenario
A user wants to check foreign words, names, or specialized terms listed in a separate Word document against a manuscript.
Observed behavior
The desired result is a new document containing word-list entries that do not appear in the manuscript.
Before you start

Place each word or phrase on its own paragraph in the word-list document, then open the manuscript in desktop Microsoft Word. Use this macro in Word for Windows and run macros only from trusted sources.

Solution 1Recommended

Run a Word VBA macro to list missing entries

Use this macro to select a word-list document and generate a separate report of entries not found in the active manuscript.

The comparison is case-insensitive and searches for each complete list entry as a text substring in the manuscript's main text. It does not enforce whole-word boundaries, so an entry can match part of a longer word.

The macro uses a numeric file-picker constant and an Object variable, so it does not require a named Office file-dialog constant in the code.

1
Open the VBA editor

In Word for Windows, open the manuscript, press Alt+F11, and select Insert > Module.

2
Add the macro

Paste this code into the module: Sub ListMissingEntries() Dim manuscript As Document Dim wordList As Document Dim report As Document Dim picker As Object Dim para As Paragraph Dim entry As String Dim manuscriptText As String Set manuscript = ActiveDocument manuscriptText = manuscript.Content.Text Set picker = Application.FileDialog(3) With picker .Title = "Select the document containing the word list" .Filters.Clear .Filters.Add "Word documents", "*.doc; *.docx; *.docm" .AllowMultiSelect = False If .Show <> -1 Then Exit Sub Set wordList = Documents.Open(FileName:=.SelectedItems(1), ReadOnly:=True) End With Set report = Documents.Add report.Content.InsertAfter "Entries not found in the manuscript:" & vbCr For Each para In wordList.Paragraphs entry = para.Range.Text entry = Replace(entry, Chr(13), "") entry = Replace(entry, Chr(7), "") entry = Trim(entry) If Len(entry) > 0 Then If InStr(1, manuscriptText, entry, vbTextCompare) = 0 Then report.Content.InsertAfter entry & vbCr End If End If Next para End Sub

3
Run the comparison

Return to the manuscript so it is the active document. Select View > Macros > View Macros, choose ListMissingEntries, and select Run.

4
Select the list and save the report

In the file picker, select the Word document containing the list. Review the new report document and use File > Save As to save it.

Run a Word VBA macro to list missing entries
If the file-picker line fails: Confirm that the macro is running in desktop Word for Windows. If using code that declares Office file-dialog types or named constants, open Tools > References in the VBA editor and check the Microsoft Office object library; the example above uses late binding instead.
Free Microsoft Office alternative

Review Word Documents with WPS Writer

WPS Office is a free, lightweight alternative for opening and editing Word documents in a familiar interface. Its Microsoft Office format compatibility makes it easier to move manuscripts and word lists between suites; it does not fix Microsoft Word VBA errors.

Open and review manuscripts and word-list documentsCompatible with Microsoft Word DOC and DOCX formatsFamiliar editing interface for an easier transitionFree, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Does the macro match whole words only?

No. It uses InStr to look for each list entry anywhere in the manuscript's main text, so a short entry can match part of a longer word.

Does the comparison distinguish uppercase and lowercase letters?

No. The macro uses vbTextCompare, making the comparison case-insensitive.

Why does Application.FileDialog cause an error?

Check that you are running the macro in desktop Word for Windows. If your code uses named Office file-dialog types or constants, check Tools > References in the VBA editor for the Microsoft Office object library. The example uses an Object variable and the numeric file-picker constant instead.

Can the word list contain phrases?

Yes. Put each phrase in its own paragraph; the macro searches for the entire paragraph text as a substring in the manuscript.

Will the report include entries found only in headers or footers?

The macro searches the manuscript's main text through Document.Content. Entries found only in headers or footers can therefore appear in the missing-entries report.