How to retrieve value from Content Controls using Word VBA
The following snippet validates the user selection using VBA. This code uses the content control created in previous example - (How to add Content Controls using VBA)
Sub Validate_ContentControl()
Dim oCC As ContentControl
Dim OCCEntry As ContentControlListEntry
Set oCC = ActiveDocument.ContentControls(1)
For i = 1 To oCC.DropdownListEntries.Count
If oCC.DropdownListEntries.Item(i).Text = oCC.Range.Text Then
Set OCCEntry = oCC.DropdownListEntries.Item(i)
' Check the text against value - can be checked directly with text
If OCCEntry.Value = 1 Then
MsgBox "Correct"
Else
MsgBox "Try Again"
Exit Sub
End If
End If
Next i
- Login or register to post comments
- Feed: vbadb feed
- Original article
