How to Create a VBA Macro to Cycle Through Custom Word Replacements
Question details
The user needs a method to dynamically replace a specific word with a series of custom alternatives, cycling through them each time a macro is executed.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Editing a document where specific terms need to be repeatedly swapped with predefined custom synonyms or variations stored in a database or table.
- Observed behavior
- The goal is to automatically replace the word near the cursor with the next available option from a custom data table, cycling back to the original word after the last option is used.
Before writing the macro, ensure the Developer tab is enabled in your Word ribbon and map out a clear list of the original words alongside their corresponding custom replacement options.
Create a VBA Macro with a Replacement Data Table
Build a custom VBA script that references an array or a built-in table to cycle through customized word replacements dynamically.
Writing a VBA macro is the most effective way to handle customized replacement cycles. You will need to create a data structure that stores the original word, its replacement options, and tracks the current position in the cycle.
The script will identify the word nearest to your text cursor, look up its replacement list, insert the next available option, and update the cycle position tracker.
Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window. Go to Insert > Module to create a blank workspace for your code.
Set up an array or reference a hidden Word table in your code that contains your base words and their respective synonyms. Include an integer variable to track the current index of the cycle.
Use the Selection.Words(1) object to capture the word currently adjacent to the cursor. Program the macro to match this selected word against your database.
Write logic to replace the selected text with the next string in your array. Add a conditional statement (If/Then) to reset the index tracker back to the first option once the end of the replacement list is reached.
Use the Built-in Thesaurus for Small Replacements
If you only have a few words to replace and do not require an automated custom cycle, utilizing the built-in thesaurus is much faster.
Easily Replace Words and Find Synonyms in WPS Office
While writing custom VBA scripts can be complex, WPS Office provides built-in tools like an extensive Thesaurus and advanced Find and Replace features to quickly cycle through and update terminology in your documents without any coding.
- 1. Open Your Document: Launch WPS Writer and open the document containing the words you want to replace.
- 2. Highlight the Text: Double-click the specific word you want to find an alternative for.
- 3. Use the Synonyms Tool: Right-click the highlighted text and select 'Synonyms' to view a list of contextually appropriate alternatives.
- 4. Apply the Replacement: Click the desired synonym from the dropdown list to instantly swap out the original word.

Frequently Asked Questions
Can I use this replacement macro across multiple Word documents?
Yes. If you save your VBA macro in the Normal.dotm template rather than a specific document, the macro and its shortcut will be accessible in all new and existing Word documents you open on your computer.
How do I store the custom replacement database?
You can store your replacement relationships in several ways: hardcoded arrays within the VBA script, a standard table at the end of your document, a separate text file, or an external Excel spreadsheet that the macro reads when executed.
What happens when the macro reaches the end of my replacement list?
The macro should be explicitly programmed to track the current index. Once it outputs the final alternative in your dataset, the logic must reset the index counter to zero, which will cycle the text back to the original word on the next run.




