VBA & Macro Problems

Fix Cascading Drop-Down VBA Errors in Microsoft Word

Tauseeq MagsiTauseeq Magsi Nov 18, 2026 870 views

Question details

Fix a VBA compile error and populate a dependent drop-down list in a Word document.

Fix Cascading Drop-Down VBA Errors in Microsoft Word
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.
Before you start

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.

Solution 1Recommended

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.

1
Check control titles

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.

2
Add the event code

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

3
Compile the project

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.

4
Test the selections

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.

Correct the VBA structure and rebuild the dependent list
Adapt the values to your document: The example uses Val to read a number at the start of the source control's displayed text. Replace the cases if your source displays other text. The dependent title must identify exactly one drop-down content control.
Free Microsoft Office alternative

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.

Review and edit document text while working on a drop-down formCompatible with Microsoft Word formats, including DOC and DOCXFamiliar editing interface for an easier transitionFree, lightweight tools for everyday document work
microsoft office alternative - wps office

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.