iterating child objects of a content control

A

Angus

Hello

I have a parent content control which encloses a table. In VBA I can
access the collection of content controls with a specific tag. But I
now want to iterate through the table contents. For example I have a
content control within the table which encloses a checkbox. I want to
go to this 'sub' content control within table and find out if it is
checked or not.

How would I go about iterating through the content controls 'within'
the top level conent control for the table?

Angus
 
J

Jay Freedman

Angus said:
Hello

I have a parent content control which encloses a table. In VBA I can
access the collection of content controls with a specific tag. But I
now want to iterate through the table contents. For example I have a
content control within the table which encloses a checkbox. I want to
go to this 'sub' content control within table and find out if it is
checked or not.

How would I go about iterating through the content controls 'within'
the top level conent control for the table?

Angus

Sample code:

Dim outerCC As ContentControl
Dim innerCC As ContentControl
Dim oTbl As Table
Dim oRg As Range

Set outerCC = _
ActiveDocument.SelectContentControlsByTag("myTag").Item(1)
Set oTbl = outerCC.Range.Tables(1)
Set oRg = oTbl.Range

For Each innerCC In oRg.ContentControls
MsgBox innerCC.Tag
Next

Your example is confusing because there is no such thing as a checkbox
content control. If you need that functionality, see
http://gregmaxey.mvps.org/Custom_CC_Checkboxes.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
A

Angus

Sample code:

    Dim outerCC As ContentControl
    Dim innerCC As ContentControl
    Dim oTbl As Table
    Dim oRg As Range

    Set outerCC = _
        ActiveDocument.SelectContentControlsByTag("myTag").Item(1)
    Set oTbl = outerCC.Range.Tables(1)
    Set oRg = oTbl.Range

    For Each innerCC In oRg.ContentControls
        MsgBox innerCC.Tag
    Next

Your example is confusing because there is no such thing as a checkbox
content control. If you need that functionality, seehttp://gregmaxey.mvps..org/Custom_CC_Checkboxes.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroupso
all may benefit.

There is one content control bounding each table and another content
control within the table which bounds a checkbox. The checkbox is
somehow within the table? Maybe not a standard checkbox. We can get
to inner content control. We now want to get to the checkbox within
the inner content control. how do we do that?
 
J

Jay Freedman

Angus said:
There is one content control bounding each table and another content
control within the table which bounds a checkbox. The checkbox is
somehow within the table? Maybe not a standard checkbox. We can get
to inner content control. We now want to get to the checkbox within
the inner content control. how do we do that?

This might be a bit more general than you asked for, because it allows for
the inner content control to contain zero, one, or more formfields; it does
something only when it finds one or more checkboxes.

Dim outerCC As ContentControl
Dim innerCC As ContentControl
Dim oTbl As Table
Dim oRg As Range
Dim oFF As FormField

Set outerCC = _
ActiveDocument.SelectContentControlsByTag("myTag").Item(1)
Set oTbl = outerCC.Range.Tables(1)
Set oRg = oTbl.Range

For Each innerCC In oRg.ContentControls
For Each oFF In innerCC.Range.FormFields
If oFF.Type = wdFieldFormCheckBox Then
MsgBox oFF.Name & " = " & oFF.CheckBox.Value
End If
Next
Next

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top