Set a Word Content Control Value with VBA
Question details
Find a Word plain-text content control by title and set its content or placeholder using VBA.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A user wants to update a content control titled LastName without looping through every control in the document.
- Observed behavior
- SelectContentControlsByTitle returns a collection, so the code must select an item before updating the control.
In Word, select the content control and open Developer > Properties to check its Title. Make sure the document is open and that macros are enabled only if you trust their source.
Set the content control text by title
Use the first matching control's Range.Text property to replace its actual content.
SelectContentControlsByTitle returns a collection. The index (1), or Item(1), selects the first matching control; use another index if you need a different match.
In Word, open Developer > Visual Basic, then select Insert > Module in the VBA editor.
Paste this macro into the module: Sub SetLastName() Dim matches As ContentControls Set matches = ActiveDocument.SelectContentControlsByTitle("LastName") If matches.Count > 0 Then matches(1).Range.Text = "Brown" Else MsgBox "No content control with that title was found." End If End Sub
Place the cursor inside SetLastName and press F5 in the VBA editor. The first control titled LastName is updated to Brown.

Change the content control placeholder
Use SetPlaceholderText when you want to change the prompt shown for an empty control rather than its actual value.
Edit Word documents with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Its format compatibility helps you move existing files into WPS; Word VBA and content control behavior may differ.

Frequently Asked Questions
Why does SelectContentControlsByTitle need an index?
It returns a collection because more than one control can have the same title. Use (1) or Item(1) to select the first match, and check the collection's Count before selecting an item.
How do I change the control's value instead of its placeholder?
Use the selected control's Range.Text property, such as ActiveDocument.SelectContentControlsByTitle("LastName")(1).Range.Text = "Brown".
Where can I find a content control's title?
Select the control in Word and choose Developer > Properties. Check the Title field and use that title in SelectContentControlsByTitle.
How do I keep the macro in my document?
In Word, choose File > Save As and select Word Macro-Enabled Document (*.docm). Enable macros only when you trust the document and its source.




