The Anchorage
Personal website of Gregory K. Maxey, Commander USN (Retired)
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
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!
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.
Note: 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.
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.
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.
Note: 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.
Representative Excel content used for examples 4 and 5 is shown below.
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.
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.
Note: No optional arguments were passed with example 1. The resulting string list is ordered according to the order the list items are defined.
After making a selection and clicking userform OK button, the document appears as shown below.
Note: 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.
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.
Note: 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.
Using as unrestricted multi-select combobox, the user may edit the resulting text directly in the document.
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.
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.
Note: 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.
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.
Only the Content Control Placeholder is defined as a property. |
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.
Notes:
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.
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"
Note: If using the strListItems argument, the pipe character "|" must be used as the delimiter.
As the bSort and bAsList arguments were set to True and passed, the resulting display is an ordered numbered list.
The restricted content is displayed in the document as shown below.
Note: As with example 1, example 5 is a restricted list that cannot be edited by the user.
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."
Note: If using the strListItems argument, the pipe character "|" must be used as the delimiter.
I'll leave is to you the reader to evaluate the arguments passed that resulted in the display shown.
Note: 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.
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.
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
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!