Template Issues

Use Word Content Controls and VBA to Insert or Remove Template Text

Khadija KhanKhadija Khan Nov 27, 2026 870 views

Question details

Create a Word template that adds or removes predefined text sections according to users' selections.

Use Word Content Controls and VBA to Insert or Remove Template Text
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.
Before you start

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.

Solution 1Recommended

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.

1
Create the 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.

2
Add selection controls

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.

3
Mark the section locations

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.

4
Write and run the macro

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.

5
Test the template

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.

Build optional template sections with content controls and VBA
Plan removal carefully: Keep optional sections inside their designated controls so the macro can remove only generated content. Test deletion behavior on a copy before using the template for production documents.
Free Microsoft Office alternative

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.

Edit optional template text manually in WPS WriterOpen and save common Microsoft Word formats, including DOCXUse a familiar interface to work with existing documentsAccess a free, lightweight Office alternative
QA img-9

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.