VBA & Macro Problems

Set a Word Content Control Value with VBA

Steve KSteve K Nov 27, 2026 868 views

Question details

Find a Word plain-text content control by title and set its content or placeholder using VBA.

Set a Word Content Control Value with 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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Word, open Developer > Visual Basic, then select Insert > Module in the VBA editor.

2
Add the update macro

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

3
Run the macro

Place the cursor inside SetLastName and press F5 in the VBA editor. The first control titled LastName is updated to Brown.

Set the content control text by title
Check duplicate titles: If multiple controls share the title, the macro changes only the first match. Check matches.Count before using a different index.
Free Microsoft Office alternative

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.

Open and edit Microsoft Word DOC and DOCX filesWork with document text in a familiar editorMove existing Word documents into a lightweight office suiteUse a free option for everyday document editing
microsoft office alternative - wps office

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.