Fix Cascading Drop-Down VBA Errors in Microsoft Word
Question details
Fix a VBA compile error and populate a dependent drop-down list in a Word document.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A document uses VBA to update one drop-down content control based on the selection in another.
- Observed behavior
- Word reports “Compile error: Expected End With,” and the dependent drop-down may remain unpopulated.
In Word, confirm that the source and dependent fields are drop-down list content controls and note their exact titles in Developer > Properties. Save the document as a macro-enabled Word document (.docm) and enable macros only if you trust the document.
Correct the VBA structure and rebuild the dependent list
Use this approach to resolve unmatched With blocks and populate the dependent list from the selected source value.
In Word, select each content control and open Developer > Properties. For the example below, set the source title to Source and the dependent drop-down title to Dependent, or change those names in the code to match your document.
Open Developer > Visual Basic. In the project for your document, open ThisDocument and add the following code. If a ContentControlOnExit procedure already exists, adapt its contents rather than adding a second procedure with the same name: Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean) Dim target As ContentControl Dim strOut As String Dim item As Variant If CC.Title <> "Source" Then Exit Sub If ThisDocument.SelectContentControlsByTitle("Dependent").Count <> 1 Then Exit Sub Set target = ThisDocument.SelectContentControlsByTitle("Dependent").Item(1) If target.Type <> wdContentControlDropdownList Then Exit Sub Select Case Val(CC.Range.Text) Case 1 To 8, 10 To 18, 26 strOut = "Per Hotel Vendor Chain" Case 9 strOut = "Per Property / per core" Case 19 To 21 strOut = "Per License|N/A" Case 22, 23 strOut = "N/A" Case 24, 25 strOut = "Per License" End Select With target.DropdownListEntries .Clear If strOut <> "" Then For Each item In Split(strOut, "|") .Add Text:=CStr(item) Next item End If End With End Sub
In the Visual Basic editor, choose Debug > Compile VBAProject. If Word highlights a With statement, check that it has a matching End With and that nested If, Select Case, and For blocks are also closed.
Return to the document, select a numeric value in Source, and then exit that control. Open Dependent to check its entries. For example, selecting 19, 20, or 21 should produce Per License and N/A.

Work with Word documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Word documents. Open compatible files to make the move easier; repairing the Word VBA event itself still requires Microsoft Word.

Frequently Asked Questions
Why does Word report “Expected End With”?
A With block may be missing its End With, or another nested block may be closed in the wrong order. Open Developer > Visual Basic and use Debug > Compile VBAProject to locate the error.
Why doesn't assigning two strings create two drop-down entries?
Assigning a second value to the same string variable replaces the first. Store values such as Per License|N/A, split the string with Split(strOut, "|"), and add each result to DropdownListEntries.
Why is the dependent list still empty after the code compiles?
Check the control titles under Developer > Properties, confirm that the dependent control is a drop-down list, and verify that the source value matches a Select Case branch. The example runs when you exit the source control.
Where should I save the ContentControlOnExit code?
In Developer > Visual Basic, place the document event procedure in ThisDocument for the relevant document. Save the file as a .docm document so it can retain the macro.




