Use Word Content Controls and VBA to Insert or Remove Template Text
Question details
Create a Word template that adds or removes predefined text sections according to users' selections.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Users select machine functions, devices, and interlocks in a template, and the document displays the corresponding text.
- Observed behavior
- The desired template uses content controls and VBA to manage optional sections from reusable building blocks.
Enable the Developer tab in Word through File > Options > Customize Ribbon, and identify the optional sections and selection rules you need. Use a macro-enabled template and ensure your organization's macro security settings permit the VBA to run.
Build optional template sections with content controls and VBA
Use this approach when selections in a Word template should determine which predefined sections appear in a document.
Keep each optional section in a separate building block and use tagged content controls as predictable insertion locations. A VBA macro can read the selection controls, clear the relevant section locations, and insert the selected building blocks.
Select each reusable text section, choose Insert > Quick Parts > Save Selection to Quick Part Gallery, and give it a unique name. Save the building blocks in the template that will be available when the macro runs.
On the Developer tab, insert a Check Box Content Control for each optional function, device, or interlock. Select each control, open Developer > Properties, and assign a unique tag that the macro can identify.
Insert a separate content control at each location where optional text should appear. Use Developer > Properties to give each location a unique tag, and design the macro to change its contents without deleting the control itself.
Open Developer > Visual Basic and add VBA to the template that finds controls by tag, reads each check box's Checked state, and clears or inserts the corresponding building block at its tagged location. Run the macro through Developer > Macros after changing selections, or connect it to a suitable document event.
Save the template as a Word Macro-Enabled Template (.dotm), create a document from it, and use Developer > Macros to test checked, unchecked, and repeated selections. Confirm that unrelated text remains intact and that each building block is available.

Edit Word-compatible templates with WPS Writer
WPS Office is a free, lightweight, easy-to-use Office alternative with a familiar interface for opening and editing Word documents. It supports common Microsoft Word formats for easier migration, but it should not be assumed to reproduce Word's content-control and VBA automation.

Frequently Asked Questions
How do I show the Developer tab in Word?
Go to File > Options > Customize Ribbon, select Developer, and choose OK. The tab provides access to content controls, macros, and the Visual Basic editor.
Where should I save the reusable text sections?
Select a section and use Insert > Quick Parts > Save Selection to Quick Part Gallery. Save it in a template that will be available to the document and its macro.
Will a check box automatically run the VBA macro?
Not by itself. You can run the macro from Developer > Macros after changing selections, or implement a suitable document event to trigger your update logic.
Why do I need a macro-enabled template?
A Word Macro-Enabled Template (.dotm) can store VBA code. Save it through File > Save As and choose the macro-enabled template format; users must also be allowed to run its macros under their security settings.




