How to Require and Repeat Project Information in a Word Template
Question details
The user wants to enforce the entry of specific details, such as a project name and code, when a new document is created from a template, and have these details automatically repeated throughout the file.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Creating standardized project documents from a template where specific details must be mandatorily filled in and perfectly mirrored across multiple pages.
- Observed behavior
- The goal is to enforce data entry upon document creation and auto-populate specific fields to maintain document consistency without requiring users to manually re-type information.
Ensure that the Developer tab is enabled in your Word ribbon, as you will need access to VBA macros and Content Controls to implement mandatory data validation and repeating fields.
Use a VBA UserForm to Collect and Repeat Data
This method prompts the user with a custom form upon document creation, ensuring required details are entered and populated throughout via DOCVARIABLE fields.
A VBA UserForm provides a structured way to gather input. By triggering it automatically when a new document is created, you can guarantee that users enter the mandatory project name and code.
The collected data is then stored as hidden Document Variables and displayed wherever needed using DOCVARIABLE fields, guaranteeing consistency across the document.
Open your template, navigate to the Developer tab, and click 'Visual Basic' to open the VBA editor.
Insert a new UserForm containing text boxes for 'Project Name' and 'Project Code', along with a 'Submit' command button.
Add code to the Submit button to validate the input (ensuring the fields are not empty), assign the values to ActiveDocument.Variables, and run an ActiveDocument.Fields.Update command.
Create an AutoNew macro in a standard module with the code to display the UserForm automatically when a new document is created from the template.
In the document body, press Ctrl+F9 to insert field braces and type DOCVARIABLE "ProjectName". Repeat this wherever the data should appear, then press F9 to update.

Apply Mapped Content Controls and Validation Macros
Mapped content controls automatically update everywhere they are copied, while a save-event macro ensures the document cannot be saved if these fields are left empty.
Create and Manage Templates Easily with WPS Office
While highly complex VBA UserForms and mapped XML tasks require Microsoft Word, WPS Office offers a robust, user-friendly, and completely free alternative for standardizing everyday document templates. It provides excellent compatibility with Word files, making everyday template creation and editing hassle-free.
- 1. Download and Install: Download and install WPS Office from the official website to get started.
- 2. Open the Template Gallery: Open WPS Writer and click on 'New' to browse the rich, built-in template gallery.
- 3. Edit and Save: Open your existing .docx or .dotx template directly, edit with familiar formatting tools, and save it locally or to the cloud.

Frequently Asked Questions
What is a DOCVARIABLE field in Microsoft Word?
A DOCVARIABLE field is used to display data stored in a hidden document variable, which is typically created via a VBA macro. It dynamically updates the text when the variable's value changes, making it ideal for displaying repeating data gathered from a UserForm.
How do mapped Content Controls work?
Mapped Content Controls are linked to a Custom XML part stored within the document's backend. When you link multiple controls to the same XML node, changing the text in one control automatically updates all other controls linked to that exact same node.
Why is my macro not running when I create a new document?
Ensure that your template is saved as a Macro-Enabled Template (.dotm) and that your Trust Center settings allow macro code execution. Also, verify that your startup macro is correctly named AutoNew or is placed within the Document_New event in the ThisDocument module.
Can I update the project information after the initial setup?
Yes. If you use a UserForm, you can write a secondary macro to display the form again, edit the fields, and refresh the DOCVARIABLE fields. If using mapped content controls, you can simply edit any of the connected controls directly on the page, and the rest will sync instantly.




