Use Word VBA to Build Machine Manuals with Content Controls and Building Blocks
Question details
Create customized machine manuals from one Word template using selections that determine which sections are included.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A template author wants to combine check boxes, content controls, building blocks, and VBA to assemble manuals for different machines.
- Observed behavior
- A user selects the relevant options, and a macro inserts the matching reusable sections into the manual.
Use desktop Word with VBA available, and enable the Developer tab through File > Options > Customize Ribbon if it is hidden. Prepare the reusable manual sections and decide on a unique tag and building block name for each option.
Insert a Building Block Based on a Word Content Control
Use this approach to assemble a new manual from a macro-enabled template and extend it with additional selectable sections.
The example uses a check box content control tagged IncludeSafety and a building block named SafetySection. It appends the section when the box is checked; it does not remove previously inserted sections.
Run the macro once on a new document created from the template. Running it again with the box checked will insert another copy.
In Word, open or create your manual template and use File > Save As to save it as a Word Macro-Enabled Template (.dotm).
On the Developer tab, select Check Box Content Control. Select the control, choose Properties, and set its Tag to IncludeSafety.
Select the safety section text, then choose Insert > Quick Parts > Save Selection to Quick Part Gallery. Name it SafetySection and select your macro-enabled template in the Save in list.
Choose Developer > Visual Basic, select the template project, and use Insert > Module. Paste this code into the module: Sub InsertSafetySection() Dim doc As Document Dim controls As ContentControls Dim destination As Range Set doc = ActiveDocument Set controls = doc.SelectContentControlsByTag("IncludeSafety") If controls.Count = 0 Then MsgBox "The IncludeSafety control was not found." Exit Sub End If If controls(1).Type <> wdContentControlCheckBox Then MsgBox "IncludeSafety must be a check box content control." Exit Sub End If If Not controls(1).Checked Then Exit Sub Set destination = doc.Range(doc.Content.End - 1, doc.Content.End - 1) On Error GoTo InsertError doc.AttachedTemplate.BuildingBlockEntries("SafetySection").Insert Where:=destination, RichText:=True Exit Sub InsertError: MsgBox "Could not insert SafetySection. Check that it is saved in the attached template." End Sub
Save the template, create a new document from it, and check IncludeSafety. Choose Developer > Macros, select InsertSafetySection, and select Run. Test again with a new document and the box unchecked.
For each additional section, add a check box through Developer, assign a unique tag in Properties, and save a uniquely named building block through Insert > Quick Parts. Extend the macro with matching tag and building block names.

Edit Machine Manuals with WPS Writer
WPS Office is a free, lightweight Office alternative with a familiar interface for creating and editing machine manuals. Its Word format compatibility helps you move documents between suites, although the Word-specific VBA workflow may not work the same way in WPS.

Frequently Asked Questions
How do I show the Developer tab in Word?
In desktop Word, go to File > Options > Customize Ribbon, check Developer, and select OK.
Where should I save the building blocks for this macro?
When you choose Insert > Quick Parts > Save Selection to Quick Part Gallery, select the macro-enabled template in the Save in list. The example searches the active document's attached template.
Why does the macro insert the same section twice?
The example appends a section each time it runs with the check box selected. Run it once on a new document, or modify the macro to identify and replace previously inserted content.
Can the macro remove a section when I clear a check box?
Not as written. To support removal, modify the VBA to identify the inserted section reliably, for example by placing it in a named content control or bookmark, before deleting or replacing it.
Can WPS Writer run this Word VBA template unchanged?
Word-specific VBA and building block behavior should not be assumed to work unchanged in WPS Writer. Use desktop Microsoft Word for the described macro workflow and test any migration separately.




