Search code examples
vbams-worddropdownbox

how to get dropdown value (not display text) from word content control using VBA


I have a drop-down content control element in my word doc. When I look at the properties of that content control, they define the "Display Name" and a "Value". I've found VBA code that shows how to grab the display text/name, but I cannot find anything that shows how to get the value information using VBA.

enter image description here

I basically want to pull the "value" field from this, and a couple of other drop-downs, to fill in a text field via VBA.


Solution

  • Try:

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