Link to home
Start Free TrialLog in
Avatar of Hawkvalley1
Hawkvalley1Flag for United States of America

asked on

How to fill several content controls in a Word2007 template?

Hi All.

Trying to fill 2 diff. content controls on my template, with the following code I get the first one to fill but not the second one, any ideas?

Dim objcc As Microsoft.Office.Interop.Word.ContentControl
            For Each objcc In oDoc.ContentControls
                If objcc.Type = WdContentControlType.wdContentControlText Then
                    If objcc.Tag = "Units" Then
                        objcc.SetPlaceholderText(Nothing, Nothing, TextBox2.Text)
                        oDoc.Content.Paragraphs.Add()
                    End If
                    If objcc.Tag = "Narrative" Then
                        objcc.SetPlaceholderText(Nothing, Nothing, TextBox1.Text)
                    End If
                End If
                Exit For
            Next
'or
 Dim objcc As Microsoft.Office.Interop.Word.ContentControl
            For Each objcc In oDoc.ContentControls
                If objcc.Type = WdContentControlType.wdContentControlText Then
                    If objcc.Tag = "Units" Then
                        objcc.Range.Text = TextBox2.Text
                        oDoc.Content.Paragraphs.Add()
                    End If
                    If objcc.Tag = "Narrative" Then
                        objcc.Range.Text = TextBox1.Text
                        End If
                End If
                Exit For
            Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of irudyk
irudyk
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hawkvalley1

ASKER

You are absolutely right, I got that from an example online - it appeared to me that it would evaluate each content then exit, appearently not, thanks for the help...
Thanks again...