How to Find Repeated Words Within a Set Distance Using VBA
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.

- 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.
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.
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.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your word processor.
Click Insert > Module from the top menu to create a blank workspace for your 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.
Press F5 or click Run from the top toolbar to execute the macro and review the highlighted repetitions in your document.

Exclude Specific Terms from the Repetition Check
Prevent character names, legal terms, or scientific jargon from being flagged as repeated errors.
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. Open WPS Writer: Launch WPS Office and open your long text document in WPS Writer.
- 2. Access the Developer Tools: Navigate to the Tools tab on the ribbon and click on Developer to reveal the Macro options.
- 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.

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.




