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
Friday, July 23, 2010
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)
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.
It is very helpful to me. Thanks!
ReplyDeleteI have a Problem it Comes an error at this line:
ReplyDeleteIf oCC.DropdownListEntries.Item(i).Text = oCC.Range.Text Then
What could be wrong ?
regards skyerjoe
Doesn't work word marked the "If oCC.DropdownListEntries.Item(i).Text = oCC.Range.Text Then"
ReplyDeleteso i think something doesn't fit
regards