How to Show or Hide Bookmarks Using Dropdowns and Checkboxes in Word
Question details
The user wants to create a macro-enabled Word template that automatically shows or hides specific groups of bookmarks based on the state of a checkbox or a dropdown selection.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating a dynamic Word form or template where document content (bookmarked text) is conditionally displayed based on user input in content controls.
- Observed behavior
- The user needs a VBA solution to trigger the ContentControlOnExit event to handle varying numbers of bookmarks correctly without throwing errors for missing placeholders.
Ensure the Developer tab is enabled in your Word ribbon and check your Trust Center settings to verify that macros are allowed to run, as IT policies sometimes disable them by default.
Use the ContentControlOnExit Event in a Macro-Enabled Template
Place VBA code in the ThisDocument module of a .dotm template to automatically show or hide bookmarks when users interact with content controls.
When a document is created from a macro-enabled template (.dotm), content controls are copied over while the VBA code remains securely in the template. Using the Document_ContentControlOnExit event ensures the macro triggers automatically when the user leaves the dropdown or checkbox.
Navigate to the Developer tab, click 'Visual Basic', and double-click 'ThisDocument' in the Project Explorer pane on the left.
Paste your Document_ContentControlOnExit and ShowHideBookmarks VBA code directly into the ThisDocument module. These are event procedures and are not intended to be run manually.
In your code, use a 'Select Case' statement to identify the user's action. For dropdowns, evaluate the selected value; for checkboxes, evaluate the checkbox's Title property.
To avoid creating placeholder bookmarks for options with fewer items, wrap your hide/show logic in a check: If ActiveDocument.Bookmarks.Exists("BookmarkName") Then. This verifies the bookmark exists before changing its Hidden property.
Go to File > Save As, and choose 'Word Macro-Enabled Template (*.dotm)' as the file format.

Experience Seamless Document Creation with WPS Office
While advanced VBA macros utilizing Microsoft-specific ContentControl events are tailored for MS Word, WPS Office provides a free, lightweight, and highly compatible alternative. Enjoy a familiar interface and seamless migration for all your standard document and template needs.

Frequently Asked Questions
Why isn't my VBA macro running when I change the dropdown selection?
The Document_ContentControlOnExit event only triggers when you exit the content control. Make sure you click outside the dropdown or press Tab after making your selection. Additionally, verify that your IT department has not disabled macros in the Trust Center settings.
Do I need to create placeholder bookmarks if some options have fewer bookmarks?
No, you do not need placeholders. You can modify your VBA code to check if a bookmark exists using 'If ActiveDocument.Bookmarks.Exists("BookmarkName")' before attempting to hide or show its range.
Where should I save my macro code for content controls?
Always save the VBA code related to content control events within the 'ThisDocument' module of your macro-enabled template (.dotm). Code placed in standard modules will not catch document-level events automatically.
How does the macro identify which checkbox or dropdown was interacted with?
For checkboxes, the macro typically evaluates the checkbox's Title property to identify it within a Select Case statement. For dropdowns, it usually evaluates the current selected text value.




