How to Insert Formatted Text and Fields in Word Using VBA
Question details
The user needs to insert pre-formatted text blocks and user-input fields dynamically based on a drop-down menu selection using VBA without losing the original styling.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating an automated Word form where selecting a specific option from a drop-down menu triggers the insertion of distinct, richly formatted instructional text and input fields.
- Observed behavior
- Standard VBA text insertion methods insert only plain text, stripping away desired visual styling (like red fonts) and removing functional form fields.
Ensure that the Developer tab is enabled in your Word ribbon to access the VBA Editor and form controls, and save your document as a Macro-Enabled Document (.docm).
Use AutoText and Building Blocks with VBA
Save your formatted text and fields as AutoText entries, then use a VBA macro to insert the appropriate block based on the user's drop-down selection.
Hardcoding formatted text directly into a VBA script often results in plain text output, stripping away colors, fonts, and form controls. The most effective approach is to design your content directly in the document and save it as a reusable Building Block.
By saving your black instructional text and red input fields as an AutoText entry, you can use a simple VBA macro to insert the block in its entirety. This method guarantees that all rich formatting, images, and embedded form fields remain perfectly intact upon insertion.
Type out your instructional text and insert your form fields exactly as required directly in the document. Apply all necessary formatting, such as black font for instructions and red font for user input fields.
Highlight the entire block of formatted text and fields. Navigate to Insert > Quick Parts > AutoText, and click 'Save Selection to AutoText Gallery'. Assign it a unique, easily identifiable name.
Press Alt + F11 to open the Visual Basic Editor. Write a macro that uses the AutoTextEntries.Insert method, referencing the unique name you just created, to insert the formatted block at a specific document bookmark or the current cursor selection.
Return to your document, right-click the drop-down form field, and open its Properties. Under the 'Run macro on' section, select your newly created macro in the 'Exit' dropdown so it triggers as soon as a selection is made.

Use WPS Writer to Manage Formatted AutoText Easily
WPS Writer offers an intuitive and highly efficient interface to create, format, and manage AutoText entries, allowing you to streamline dynamic document creation without the heavy overhead.
- 1. Download and Install: Download WPS Office Free from the official website and install it on your computer.
- 2. Format Your Content: Open WPS Writer and type out your text and fields, applying your desired colors and styling.
- 3. Save to AutoText: Highlight the styled content, go to the Insert tab, click on Quick Parts, and save it as an AutoText entry.
- 4. Insert Instantly: Use the Quick Parts menu to instantly drop your perfectly formatted text blocks into any document whenever needed.

Frequently Asked Questions
Why does my VBA script lose text formatting when inserting text?
When you use VBA string assignment (e.g., Selection.Text = "my text"), the application only processes plain text. To preserve colors, custom fonts, and embedded objects, you must utilize Building Blocks, AutoText, or the FormattedText property.
How do I trigger a VBA macro immediately after a drop-down selection?
You can attach a macro to a legacy form field drop-down by opening the field's properties and setting the 'Run macro on Exit' option. When the user makes a choice and tabs to the next field, the designated macro executes automatically.
Can I insert images alongside formatted text using AutoText via VBA?
Yes. Any element that can be selected in your document, including images, tables, and functional form fields, can be combined and saved as a single AutoText entry. Your VBA script will insert the entire entry completely intact.




