Search code examples
vbaindexingdrop-down-menums-wordword-contentcontrol

How to return the index or list number from a MS Word ContentControl Dropdown box


I have a content controlled dropdown box created in Word. I need to be able to capture the index number of the chosen item in the box. I already know how to capture the text itself after someone selects an item.
That code is: curVal = ContentControl.Range.Text but I can not figure out how to capture the index.


Solution

  • That's as simple as:

    Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
    Dim i As Long
    With CCtrl
      For i = 1 To .DropdownListEntries.Count
        If .DropdownListEntries(i).Text = .Range.Text Then
          MsgBox i: Exit For
        End If
      Next
    End With
    End Sub