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
Welcome to VBA Tips & Tricks. All VBA related information will be posted on this blog. Of late, VBA has been disregarded by many software professionals for .Net, c# and other technologies. This blog will also post articles related to them too Happy reading
Pages
▼
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)
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