Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

(Pseudo) Multi-Select Content Control Dropdown Lists
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

This Microsoft Word Tips & Microsoft Word Help page illustrates methods to permit "the apparent" selection of one or more defined dropdown list entries from a dropdown or combobox type content control.

Site Note IconNote: All methods described in this tips page require a macro enabled document.  If you or your users are prevented from using macro enabled documents by company IT security policies then STOP and read no further. 

It is an unfortunate fact that Microsoft has failed miserably in expanding content control capabilities to match those of the age old ActiveX controls and more common userform controls.  A multi-select dropdown/combobox content control just doesn't exist.

MS_CCs_1

When Microsoft fails, the determined must roll up their sleeves and improvise.

By leveraging the built-in Document_ContentControlOnEnter event, a document designer can create functioning "pseudo" dropdown content controls by employing a userform and a little creative VBA.

The Document_ContentControlOnEnter event is part of the "ThisDocument" class module in the macro enabled document VB Project.. The event detects user entry into any content control contained in the document. Therefore when the user clicks or tabs in any content control in a document the event is triggered.  The Document_ContentControlOnEnter event for the examples that follow is show below.

MS_CSs_7

When the event is triggered, the content control tag is evaluated and the content control and optional arguments are passed to the procedure "ShowMultiSelectList" in the standard module modMain. 

Site Note IconNote: For the examples that follow, the Content Controls tags are defined as Example 1-6.

All documents have a ThisDocument class module predefined in the document VB Project and all documents have a Document_ContentControlOnEnter event.  All you need to do is adapt the event code to address your specific content control tag and functional requirements.

The optional arguments which can be passed to the ShowMultiSelectList are illustrated and explained below.

MS_CCs_6

Representative Excel content used for examples 4 and 5 is shown below.

MS_CC_7

Examples

In the following six examples a single userform and VBA procedures are used.

I am including a link following these examples which you can use to download macro enabled document file (and supporting Excel file) which contains the examples, the userform and all required code.

Yes, the process if relatively complex, but with the exception of the Document_ContentControlOnEnter event code, the userform and standard code module can easily be exported and imported into any document project.

Example 1

Provides a restricted dropdown list. The list items displayed are defined as dropdown list entries in the content control properties. The user is not permitted to add to the menu or alter the resulting string.

MS_CCs_2

Site Note IconNote: No optional arguments were passed with example 1. The resulting string list is ordered according to the order the list items are defined.

MS_CCs_4

After making a selection and clicking userform OK button, the document appears as shown below.

MS_CCs_3

Site Note IconNote: Entering the content control text range triggers the userform display. To edit the content control displayed text, the user must exit and then re-enter the content control.

Example 2

Provides an unrestricted combobox (dropdown) list. As with the restricted dropdown list is example 1, the list items displayed are defined as dropdown list entries in the content control properties.

The user has define additional delimited list entries in the "User defined" text field.

The user may edit the "Resulting text string" directly before assigning the content to the document content control.

MS_CCs_5

Site Note IconNote: In example 2, the bRestricted argument is passed as False permitting the user add additional list items and modify the resulting text string. The bSort argument is passed as True resulting in a sorted resulting text string. 

MS_CCs_6

Using as unrestricted multi-select combobox, the user may edit the resulting text directly in the document.

Example 3

Provides an unrestricted combobox (dropdown) list. As with examples 1 and 2, the list items displayed are defined as dropdown list entries in the content control properties.

Three of the list entries have "variable" flags (**) indicating the user is required to fill in a variable value.

The user has define additional delimited list entries in the "User defined" text field.

MS_CCs_7

The user has selected items with a variable flag (**) and must edit the "Resulting text string" to define the variable values before assigning the content to the document content control.

MS_CCs_8

Site Note IconNote: Referring to the event code discussed above, in this example the bSort argument was not passed.  Accordingly the two user defined items were not sorted and simply appended to the end of the resulting text string.

Example 4

Provides an unrestricted combobox (dropdown) list. Unlike the previous examples, in example 4 the dropdown list items are defined in external Excel file rather than as content control properties.  Only the placeholder text is defined as a property.

Defining the the list entries in an external Excel file is useful when the document designer must manage large lists that are subject to change.

MS_CCs_9

Only the Content Control Placeholder is
defined as a property.
MS_CCs_10

The list items are defined in an
external Excel file under a column headed
"Example 4"








The Document_ContentControl_OnEnter procedure is used to identify that list entries are to be retrieved from an associated Excel file and identifies the worksheet column name used to define the list.

MS_CC_9A

MS_CC_9B

Site Note IconNotes:
      1. As coded, the associated Excel file must be in the same folder as the Word document, be named "Excel List Data.xlsx" with the sheet named "Sheet 1"  Adapt the code as required to define your custom Excel file path, file name or sheet name.
      2. The items in the Excel list are intentionally unsorted to demonstrate use of the bSort argument set to True for this example.



 MS_CCs_11

Example 5

Provides an restricted dropdown list displayed in the document as an ordered numbered list.

In this example, the list entries are defined in a user defined delimited list string. This string is declared as a variable in the ThisDocument class module as shown below. It could just as easily be passed directly e.g., passed as "apples|blueberries|peaches"

Site Note IconNote: If using the strListItems argument, the pipe character "|" must be used as the delimiter.

MS_CCs_12

As the bSort and bAsList arguments were set to True and passed, the resulting display is an ordered numbered list.

MS_CCs_14

The restricted content is displayed in the document as shown below.

MS_CCs_13

Site Note IconNote: As with example 1, example 5 is a restricted list that cannot be edited by the user.

Example 6

Provides an unrestricted combobox dropdown list displayed in the document as an ordered numbered list.

In this example, the list entries are defined in an external Excel file under a column headed "Example 6."

 

Site Note IconNote: If using the strListItems argument, the pipe character "|" must be used as the delimiter.

MS_CCs_15

MS_CCs_16

I'll leave is to you the reader to evaluate the arguments passed that resulted in the display shown.

Site Note IconNote: As it is purely impossible for either a combobox or dropdown list content control to display multi-line text, the controls used in examples 5 and 6 are actually multi-line capable plain text controls. In the demonstration document, both are locked and can only be edited with the userform.

Conclusion

While these might not be "perfect" solutions, I have used each of them with success in projects for private clients and I hope if you found this page you will find these methods useful as well.

You can download the macro enabled document used to create these examples and the supporting Excel file here:  DOWNLOAD

That's it! I hope you have found this tips page useful and informative.

Share

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

Search my site or the web using Google Search Engine

Google Search Logo