VBA & Macro Problems

How to Find Repeated Words Within a Set Distance Using VBA

Nimra MalikNimra Malik Oct 26, 2026 868 views

Question details

The user is looking for a free method to identify and highlight words or phrases that repeat within a configurable distance in a long document, including options to ignore specific terms.

How to Find Repeated Words Within a Set Distance Using VBA
Product
Word
Device & OS
not provided
Scenario
Editing or proofreading a long document to improve vocabulary variety and avoid repetitive phrasing.
Observed behavior
The user wants to set up adjustable repetition distances and word-frequency rules to flag duplicated words automatically, while successfully excluding specific terms like character or place names.
Before you start

Ensure you have saved your document before running any custom scripts, and confirm that the Developer tab is enabled in your word processor to access the VBA editor.

Solution 1Recommended

Use a VBA Macro to Highlight Repeated Words

Create a custom VBA macro to automatically scan your document and highlight words that repeat within a defined distance.

By writing a custom VBA script, you can specify exactly how many words to check between repetitions. This is the most flexible and free method to analyze word frequency and spacing.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your word processor.

2
Insert a New Module

Click Insert > Module from the top menu to create a blank workspace for your code.

3
Paste the Macro Code

Enter a VBA script designed to check duplicates within the next set of words (e.g., 100 words) and apply a highlight color to them.

4
Run the Macro

Press F5 or click Run from the top toolbar to execute the macro and review the highlighted repetitions in your document.

Use a VBA Macro to Highlight Repeated Words
Advanced Document Editing

Edit and Run Macros Easily with WPS Writer

WPS Office offers an excellent, lightweight platform for running VBA macros to analyze text patterns and find repeated words. With powerful built-in macro support in its Writer application, you can seamlessly automate complex proofreading tasks.

  1. 1. Open WPS Writer: Launch WPS Office and open your long text document in WPS Writer.
  2. 2. Access the Developer Tools: Navigate to the Tools tab on the ribbon and click on Developer to reveal the Macro options.
  3. 3. Create and Run the Macro: Click Macros, create a new module, paste your word-repetition VBA script, and click Run to highlight repeated terms.
Fully compatible with Microsoft Word .docx formats and standard VBA macro scripts.Advanced Find and Replace tools for managing custom text styles and exclusions.Free, lightweight, and features a familiar tabbed user interface.Built-in Developer tools to easily write, edit, and run text-analysis macros.
microsoft office alternative - wps office

Frequently Asked Questions

Why aren't my "Ignore in Document" choices saved when I close the file?

Word processors typically do not store the spelling checker's "Ignore in Document" choices within the document file itself. To permanently ignore specific terms, you must add them to a custom dictionary or apply a "Do Not Check Spelling or Grammar" character style to the text.

Can I set different repetition distances for common vs. rare words?

Standard VBA macros apply a fixed distance (e.g., checking within 100 words). To vary repetition distances based on word frequency, you would need to write an advanced macro that references an external word-frequency database to assign custom thresholds dynamically.

Is there a built-in feature to find repeated words within a set distance?

No, standard word processors do not have a native feature to find repeated words based on a specific distance threshold. You must use a custom VBA macro or rely on specialized third-party editing add-ins to achieve this level of analysis.