VBA & Macro Problems

Find Word Content Control Text by Tag, Title, or ID with VBA

Steve KSteve K Nov 13, 2026 868 views

Question details

The user wants to retrieve text from a Word content control using VBA by targeting the control's Tag, Title, or ID instead of its index.

Find Word Content Control Text by Tag, Title, or ID with VBA
Product
WPS Office Writer (Word VBA)
Device & OS
not provided
Scenario
The user is automating a Word document and needs a stable way to locate a specific content control even when controls are added, deleted, or reordered.
Observed behavior
Index-based references can change when controls are added or reordered; the user needs a stable Tag, Title, or ID lookup for the content control text.
Before you start

Open the document in WPS Office Writer or Microsoft Word, enable the Developer tab, and open the VBA editor. Identify whether the target content control has a unique Tag, Title, or ID before writing the lookup code.

Solution 1Recommended

Retrieve Content Control Text by Title or Tag with VBA

Use SelectContentControlsByTitle or SelectContentControlsByTag when the control is identified by a title or tag. These methods return a collection, so check Count and iterate when titles or tags are not unique.

Titles and tags are not required to be unique, and the filtering methods are case-sensitive. Iterating the filtered collection is faster than looping through all content controls.

1
Open the VBA editor

In WPS Office Writer or Word, click the Developer tab, then click Visual Basic, or press Alt+F11.

2
Insert a module

In the VBA editor, click Insert > Module to create a new standard module.

3
Enter the title or tag lookup code

Paste a macro that calls ActiveDocument.SelectContentControlsByTitle("Your Title") or ActiveDocument.SelectContentControlsByTag("Your Tag"), checks .Count, and reads .Item(1).Range.Text.

4
Run the macro

Place the cursor in the macro and press F5, or click Run > Run Sub/UserForm.

Retrieve Content Control Text by Title or Tag with VBA
Case-sensitive lookup: SelectContentControlsByTitle and SelectContentControlsByTag are case-sensitive. If you are unsure of the exact case, loop through ActiveDocument.ContentControls and compare properties case-insensitively.

Retrieve Word Content Control Text by Tag, Title, or ID in WPS Office

WPS Office Writer supports the Word VBA content control object model, so you can use tag, title, or ID lookups to return control text without relying on a shifting index. Open the VBA editor, insert a module, and run the lookup macro directly in WPS Office.

  1. 1. Open WPS Office Writer: Launch WPS Office Writer and open the .docx or .docm document that contains the content controls.
  2. 2. Open the VBA editor: Click the Developer tab and choose Visual Basic, or press Alt+F11.
  3. 3. Insert a module: In the VBA editor, click Insert > Module to create a standard module.
  4. 4. Add and run the lookup code: Paste a macro that uses ActiveDocument.ContentControls("ID"), SelectContentControlsByTitle, or SelectContentControlsByTag, then press F5.
  5. 5. Verify returned text: Use MsgBox or Debug.Print to confirm that the macro returns the content control text.
Retrieve content control text by Tag, Title, or ID without fragile index referencesOpen .docx and .docm files with familiar Word VBA content control objectsFree and lightweight Office suite with a familiar ribbon and macro editorFull compatibility with Microsoft Word document formats and VBA macrosUse with WPS Office Writer or Microsoft Word for flexible document automation
microsoft office alternative - wps office

Frequently Asked Questions

How do I find the ID of a content control in Word VBA?

Run a VBA loop over ActiveDocument.ContentControls and print each control's .ID and .Title to the Immediate Window. For example: For Each cc In ActiveDocument.ContentControls: Debug.Print cc.ID, cc.Title: Next cc. Open the Immediate Window by pressing Ctrl+G in the VBA editor.

Are SelectContentControlsByTitle and SelectContentControlsByTag case-sensitive?

Yes. Both methods perform case-sensitive matching. If you need case-insensitive matching, iterate through ActiveDocument.ContentControls and compare cc.Title or cc.Tag using StrComp with vbTextCompare.

What happens if multiple content controls have the same title or tag?

SelectContentControlsByTitle and SelectContentControlsByTag return a collection of all matching controls. Check the Count property and use Item(1), Item(2), or a For Each loop to process each match.

Why should I avoid retrieving content control text by index?

Index-based references such as ActiveDocument.ContentControls(1) can change when controls are added, deleted, or reordered. A unique ID remains stable, and unique titles or tags are easier to maintain.

Can WPS Office Writer run Word content control VBA macros?

Yes. Open the document in WPS Office Writer, enable the Developer tab, click Visual Basic, and use the same Word VBA content control methods such as SelectContentControlsByTitle, SelectContentControlsByTag, and ContentControls("ID").