VBA & Macro Problems

How to Replace AutoText Codes with Full Paragraphs via VBA

Huda QurayshiHuda Qurayshi Oct 26, 2026 868 views

Question details

The user needs to scan a document for specific code phrases and automatically replace them with corresponding long AutoText paragraphs.

How to Replace AutoText Codes with Full Paragraphs via VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Insert a New Module

Navigate to the top menu and select Insert > Module to create a blank script window.

3
Write the Loop Script

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.

4
Execute the Replacement

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.

Use a VBA Macro to Replace AutoText Entries
Updating Existing Content: Once an AutoText entry is inserted, it becomes ordinary document text. To update text that has already been expanded, you must use the standard Find and Replace (Ctrl+H) tool.
Efficient Document Automation

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. 1. Open your Document: Launch WPS Writer and open the document where you need to insert boilerplate text.
  2. 2. Configure AutoText: Navigate to the 'Insert' tab, select 'AutoText', and save your long paragraphs with easily recognizable short names.
  3. 3. Insert Instantly: Type the short name in your document and press F3 to instantly expand it into the full paragraph.
Seamlessly compatible with Microsoft Word macro-enabled documents (.docm).Built-in AutoText tools for fast, code-based paragraph insertion.Lightweight and completely free to download.
microsoft office alternative - wps office

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.