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 will show you how to link a pair of content control drop-down lists. Linked drop-down lists allow you to set the list entries that display in a dependent (secondary) content control based on the selection made in a primary content control as shown in the following illustrations:
The first step in creating linked content control drop-down lists is building the master content control and defining its properties:
Next create the secondary (dependent) content control and define its properties:
The final step is to add the VBA procedures that establish the link between the content controls. The code is added to the ContentControl_OnExit event procedure that you create in the "ThisDocument" class module of the VBA project.
Option Explicit Dim i As Long Private Type ListData arrFood() As String End Type Private Sub Document_ContentControlOnEnter(ByVal CC As ContentControl) 'Delete next line if you are using Word2010 exclusively If Application.Version < "14.0" Then Main.SetDeveloperTabActive Select Case CC.Tag Case Is = "Food Group" With ActiveDocument.SelectContentControlsByTitle("Food Item").Item(1) For i = .DropdownListEntries.Count To 2 Step -1 .DropdownListEntries(i).Delete Next i .DropdownListEntries(1).Select End With CC.DropdownListEntries(1).Select End Select lbl_Exit: Exit Sub End Sub Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean) Dim tData As ListData 'Delete next line if you are using Word2010 exclusively IF Application.Version < "14.0" Then Main.SetDeveloperTabActive Select Case CC.Tag Case Is = "Food Group" tData = GetLEData(CC) With ActiveDocument.SelectContentControlsByTitle("Food Item").Item(1) For i = .DropdownListEntries.Count To 2 Step -1 .DropdownListEntries(i).Delete Next i For i = 0 To UBound(tData.arrFood) .DropdownListEntries.Add tData.arrFood(i) Next i .DropdownListEntries(1).Select End With End Select lbl_Exit: Exit Sub End Sub Private Function GetLEData(ByRef oCCPassed) As ListData For i = 1 To oCCPassed.DropdownListEntries.Count If oCCPassed.Range.Text = oCCPassed.DropdownListEntries(i).Text Then GetLEData.arrFood() = Split(oCCPassed.DropdownListEntries(i).Value, "|") Exit For End If Next i lbl_Exit: Exit Function End Function
Note: The code provided above contains a call to a separate procedure that forces the "Developer" tab to display if used with Word 2007. This is required to work around the bug described in Content Controls. The code involved is too long to post here so it is included in two separate standard code modules ("Main" and "Accessibility") in the demonstration file that you can download at the end of this tips page. The document file also contains examples of several methods that you can use to set value of one or more plain text content controls based on the selection made in a content control drop-down list.
That's it! I hope you have found this tips page useful and informative. Download the demonstration document I used to prepare this tips page here: Linked CCs
Do you want to make a payment for consulting work or donate to help support this site?
PayPal is a safe, easy way to pay online.
Use the appropriate currency "Donate" button to make a payment or donation.