How to Replace AutoText Codes with Full Paragraphs via VBA
Question details
The user needs to scan a document for specific code phrases and automatically replace them with corresponding long AutoText paragraphs.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating the expansion of text abbreviations into full paragraphs when the text exceeds the 255-character VBA limit of AutoCorrect.
- Observed behavior
- A VBA macro is required to loop through AutoText entries and replace matching text codes in the active document with full paragraphs.
Ensure your document is saved as a Macro-Enabled Document and that your AutoText entries are correctly configured in your active template before running VBA scripts.
Use a VBA Macro to Replace AutoText Entries
Run a custom VBA macro that loops through all AutoText entries in your attached template and replaces their names in the document with the full text.
This method is ideal for text-only entries and successfully bypasses the 255-character limit of AutoCorrect.
Note that inserting tables, text boxes, and other complex objects via this macro may produce unpredictable formatting results.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
Navigate to the top menu and select Insert > Module to create a blank script window.
Write a VBA script that loops through the AutoTextEntries collection of your attached template. Use the Find object to locate the entry name (e.g., D6.14) in the active document.
Set the script to insert the corresponding AutoTextEntry.Value in place of the matched code. Press F5 to run the macro and expand all codes in the document.

Edit Building Blocks for Future Insertions
Manage and edit your AutoText blocks using the Building Blocks Organizer for manual insertion.
Easily Manage AutoText and Macros in WPS Writer
WPS Writer fully supports VBA macros and AutoText features, allowing you to quickly insert long paragraphs using short codes without worrying about strict character limitations.
- 1. Open your Document: Launch WPS Writer and open the document where you need to insert boilerplate text.
- 2. Configure AutoText: Navigate to the 'Insert' tab, select 'AutoText', and save your long paragraphs with easily recognizable short names.
- 3. Insert Instantly: Type the short name in your document and press F3 to instantly expand it into the full paragraph.

Frequently Asked Questions
Why can't I use AutoCorrect for long paragraphs?
AutoCorrect has a 255-character limitation when manipulated via VBA. This makes it unsuitable for replacing short codes with full, multi-sentence paragraphs, which is why AutoText combined with a loop macro is recommended.
Will the VBA macro automatically update AutoText I've already inserted?
No. Once an AutoText entry is inserted into the document, it loses its link to the original entry and becomes standard text. You must use the Find and Replace feature to update previously inserted paragraphs.
Can this VBA macro replace codes with tables or images?
While AutoText supports complex objects, using a VBA find-and-replace macro for tables, text boxes, or images may produce unpredictable formatting results. The macro approach works best for text-only entries.




