Document Editing Problems

Populate a Word Combo Box with Bookmark Text Using VBA

John WilsonJohn Wilson Nov 25, 2026 869 views

Question details

Populate a combo-box content control with equipment names stored in Word bookmarks.

Populate a Word Combo Box with Bookmark Text Using VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
A Word template stores equipment names in bookmarks, including bookmarks inside content controls and tables in a header.
Observed behavior
The combo box should list bookmark text from the intended document or header range.
Before you start

Open the document created from the template in desktop Word and enable the Developer tab under File > Options > Customize Ribbon if needed. Confirm which section and header contain the equipment bookmarks, and ensure the bookmarks enclose the text rather than marking empty insertion points.

Solution 1Recommended

Populate the combo box from bookmarks in the primary header

Use this VBA macro when the equipment bookmarks are in the primary header of the first section and the combo box is in the document body.

The macro reads the header range directly, so bookmarks inside a header table can be included. It removes paragraph and table-cell markers, skips empty or overlong text, and avoids duplicate entries.

1
Tag the combo box

On the Developer tab, insert or select a Combo Box Content Control in the document body. Select Properties, set its Tag to EquipmentList, and choose OK.

2
Add the VBA macro

Open Developer > Visual Basic, choose Insert > Module, and paste this code: Sub PopulateEquipmentList() Dim doc As Document Dim controls As ContentControls Dim combo As ContentControl Dim bm As Bookmark Dim entry As ContentControlListEntry Dim headerRange As Range Dim itemText As String Dim duplicate As Boolean Set doc = ActiveDocument Set controls = doc.SelectContentControlsByTag("EquipmentList") If controls.Count <> 1 Then MsgBox "Place exactly one control tagged EquipmentList in the document body." Exit Sub End If Set combo = controls(1) If combo.Type <> wdContentControlComboBox Then MsgBox "The EquipmentList control must be a combo box." Exit Sub End If Set headerRange = doc.Sections(1).Headers(wdHeaderFooterPrimary).Range combo.DropdownListEntries.Clear For Each bm In headerRange.Bookmarks itemText = Replace(bm.Range.Text, Chr(13), " ") itemText = Replace(itemText, Chr(7), "") itemText = Trim(itemText) If Len(itemText) > 0 And Len(itemText) <= 255 Then duplicate = False For Each entry In combo.DropdownListEntries If StrComp(entry.Text, itemText, vbTextCompare) = 0 Then duplicate = True Exit For End If Next entry If Not duplicate Then combo.DropdownListEntries.Add Text:=itemText End If Next bm MsgBox combo.DropdownListEntries.Count & " entries added." End Sub

3
Run and check the list

Return to Word, choose Developer > Macros, select PopulateEquipmentList, and choose Run. Open the combo box to check the entries; if the list is empty, verify the bookmarks and header section.

Populate the combo box from bookmarks in the primary header
Adjust the source range: For another section, change Sections(1) to the appropriate section number. For a different header type, replace wdHeaderFooterPrimary with wdHeaderFooterFirstPage or wdHeaderFooterEvenPages. The macro clears existing combo-box entries before adding new ones.
Free Microsoft Office alternative

Edit Word Documents with WPS Writer

WPS Office is a free, lightweight alternative for editing documents in a familiar interface. Its Word format compatibility makes it easy to move everyday document work between Office suites; it does not fix or guarantee support for this Microsoft Word VBA macro.

Edit documents in a familiar Writer interfaceOpen and edit Microsoft Word DOC and DOCX filesWork with tables and headers in documentsMove everyday document editing to a lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does my combo box stay empty when the bookmarks are in a header?

The macro may be examining the main document range instead of the header. Use the relevant section's Headers collection, such as ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range, and loop through that range's bookmarks.

Can the macro read bookmarks inside a table in the header?

Yes. Loop through the correct header range's Bookmarks collection and read each bookmark's Range.Text. Remove end-of-cell markers with Replace(text, Chr(7), "") before adding an entry.

Why is a bookmark not added to the list?

Check that the bookmark encloses text and is in the selected header. The sample macro skips empty text, text longer than 255 characters, and entries that duplicate an existing item.

How do I use bookmarks from the first-page or even-page header?

In the macro's Headers entry, replace wdHeaderFooterPrimary with wdHeaderFooterFirstPage or wdHeaderFooterEvenPages, and use the section number containing the bookmarks.

Where do I run the macro?

In desktop Word, open Developer > Macros, select PopulateEquipmentList, and choose Run. Store the macro in a macro-enabled document or template and enable macros only when you trust their source.