VBA & Macro Problems

Build a Defined-Terms Checker in Microsoft Word with VBA

Adam DavisAdam Davis Nov 20, 2026 869 views

Question details

Create a Word VBA macro that identifies likely defined terms and exports their locations for review.

Build a Defined-Terms Checker in Microsoft Word with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
Review a document for capitalized single-word and multiword terms, with page references and links to their occurrences.
Observed behavior
The desired output is a review document containing checkbox symbols, candidate terms, page numbers, and links to the source document.
Before you start

Save the source document to a local location and make sure it is editable: the macro adds bookmarks to it. Enable macros according to your organization's security policy and use a version of Word that supports the VBA editor.

Solution 1Recommended

Create a VBA macro to export candidate terms and locations

Use this macro to list each matching occurrence in a new Word document, with a checkbox symbol, page number, and link.

The macro scans the main document body for consecutive capitalized words. It skips candidates at the start of a paragraph or immediately after sentence-ending punctuation, so it may miss a defined term that appears only in those positions.

Each occurrence gets its own row and bookmark; the macro does not group duplicates or determine whether a candidate is a legal definition. It does not scan headers, footers, text boxes, or other stories.

1
Open the VBA editor

Open the saved source document in Word, then open the VBA editor from Developer > Visual Basic. In the editor, choose Insert > Module.

2
Paste the macro

Paste the following code into the module: Sub ExportDefinedTermCandidates() Dim src As Document, report As Document Dim para As Paragraph, hit As Object, hits As Object Dim re As Object, target As Range, linkRange As Range, outRange As Range Dim text As String, term As String, mark As String, prefix As String Dim i As Long, j As Long, pos As Long, pageNum As Long Dim previous As String, atStart As Boolean Set src = ActiveDocument If src.Path = "" Or src.ReadOnly Then MsgBox "Save the source document locally and make sure it is editable." Exit Sub End If src.Repaginate Set re = CreateObject("VBScript.RegExp") re.Global = True re.IgnoreCase = False re.Pattern = "\b[A-Z][A-Za-z0-9]*(?:[ \t]+[A-Z][A-Za-z0-9]*)*\b" prefix = "_DTC" & Format(Now, "yymmddhhnnss") Set report = Documents.Add For Each para In src.Paragraphs text = para.Range.Text Set hits = re.Execute(text) For Each hit In hits j = hit.FirstIndex Do While j > 0 previous = Mid$(text, j, 1) If previous <> " " And previous <> vbTab Then Exit Do j = j - 1 Loop atStart = (j = 0) If Not atStart Then previous = Mid$(text, j, 1) atStart = (previous = "." Or previous = "!" Or previous = "?") End If If Not atStart Then i = i + 1 term = hit.Value mark = prefix & CStr(i) Set target = src.Range(para.Range.Start + hit.FirstIndex, _ para.Range.Start + hit.FirstIndex + hit.Length) pageNum = target.Information(wdActiveEndPageNumber) src.Bookmarks.Add Name:=mark, Range:=target pos = report.Content.End - 1 Set outRange = report.Range(pos, pos) outRange.InsertAfter ChrW(&H2610) & " " & term & " (page " & pageNum & ")" & vbCr Set linkRange = report.Range(pos + 2, pos + 2 + Len(term)) report.Hyperlinks.Add Anchor:=linkRange, Address:=src.FullName, _ SubAddress:=mark End If Next hit Next para report.Activate MsgBox i & " candidate occurrences exported. Save both the source and this report." End Sub

3
Run the checker

Return to the source document, select Developer > Macros, choose ExportDefinedTermCandidates, and click Run. Word creates a new review document.

4
Save and review the results

Save the source document so its new bookmarks persist, then use File > Save As to save the review document. Review each candidate and follow a term hyperlink to check its context.

Create a VBA macro to export candidate terms and locations
Review the matches: Checkboxes are symbols, not interactive controls. Page numbers reflect pagination when the macro runs and may change after editing. Moving or renaming the source can break report links.
Free Microsoft Office alternative

Review Word documents with WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for opening and reviewing Word documents. Its format compatibility helps you move existing files into WPS; the Microsoft Word VBA macro above is not a WPS fix.

Open and review documents containing defined termsCompatible with Microsoft Word DOC and DOCX formatsFamiliar editing interface for an easier transitionFree, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why is a defined term missing from the report?

The macro skips candidates at paragraph starts and immediately after periods, question marks, or exclamation points. Check those locations manually, especially when a term appears only at the beginning of a sentence.

Does the report include every occurrence of a repeated term?

It creates a separate row for each occurrence that matches the capitalization and sentence-start rules. It does not consolidate duplicate terms.

Why do I need to save the source document after running the macro?

The macro adds bookmarks to the source as link destinations. Use File > Save on the source document before closing it so those bookmarks persist.

Are the checkboxes in the report clickable?

No. They are checkbox symbols for visual review, not interactive Word content controls. You can edit the report manually or replace the symbols with controls using Word's Developer tab.

Will the macro find terms in headers and text boxes?

No. This example scans the main document body only. Headers, footers, text boxes, and other Word stories require additional code.