Using one ccontent control across a document

R

Rich Denis

Hello. I am not sure if this is the right forum or not but thought it may be.

I have a template that I want to create. In the template there is a content
control that is where someone would enter in a client name. There are
multiple places in the document that need the same client name. I want to
find a way to make the client name propogate through the document using the
least amount of code possible.

Please advise. Thanks in advance.
 
J

Jie Wang [MSFT]

Hi Rich,

There is a way to repeat data in a content control without writing code.

To do that:

1. Insert a Content Control into the document.
2. Key in the customer name into the Content Control.
3. Select the content control.
4. Move the insert point to the place where you want the customer name to
be repeated.
5. From the Home tab in Ribbon, select Paste -> Paste Special.
6. In the Paste Special dialog, choose Paste link. And As Unformatted
Unicode Text.
7. Click OK to close the dialog.

Now you have a link where the customer name in the content control is
repeated and automatically updated.

Please kindly let me know if this is what you want.

If you have any further questions regarding this issue, please feel free to
post here.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy M.

Hi Rich,
I have a template that I want to create. In the template there is a content
control that is where someone would enter in a client name. There are
multiple places in the document that need the same client name. I want to
find a way to make the client name propogate through the document using the
least amount of code possible.
The way the designers of content controls set this up to be done is:

1. Create an XML file that reflects the data to be entered in the content
controls of the document. It does not have to reflect all the content controls
you use, but it should contain those that
- whose contents should be duplicated
- for which you want to read/write the data from an outside program
(without necessarily opening the Word application)

2. Add the XML file to the template as a CustomXMLPart. This can be done by
manually editing the dotx/dotm file zip package, or by using the object model
(with code). You need to do this only once, so you could use a VBA macro in
Normal.dot, for example.

3. The code then needs to "map" the XML node(s) in the XML to the corresponding
content controls in the template.

Once this link is established, anything typed in one control linked to a
particular XML node in the CustomXMLNode will automatically display in any
other content control linked to that same node. No macro code is required, once
the CustomXMLPart has been inserted and linked to the content controls (IOW you
only need it to set up the template, but not for use of the template).

There are any number of ways to code this. Below my signature is a set of
sample code I set up when someone asked about using more than one namespace.
That is totally irrelevant to your scenario, so don't worry about there being
two different sets of XML in the code sample. Just concentrate on how the (very
simple) XML is put into a CustomXMLPart, then linked to existing content
controls. What is important, however, is that you do need to specify a
Namespace in the XML, and that you need the Namespace in order to map the XML
nodes to the content controls.

FWIW, I don't think the approach suggested by Jie Wang will work the way you
need...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)

Sub CreateCustomXMLPart()
Dim doc As Word.Document
Dim cp1 As Office.CustomXMLPart
Dim cp2 As Office.CustomXMLPart
Dim Xml1 As String, Xml2 As String

Xml1 = "<?xml version='1.0' encoding='utf-8'?><tree>oak</tree>"
Set doc = ActiveDocument
Set cp1 = doc.CustomXMLParts.Add(Xml1) 'To add XML from string
doc.Variables("Xml1") = cp1.ID 'Store for future reference
Set cp2 = doc.CustomXMLParts.Add 'To add XML from file on disk
cp2.Load "C:\Test\Flower.xml"
doc.Variables("Xml2") = cp2.ID
End Sub

Sub LinkContentControlsToXML()
Dim doc As Word.Document
Dim cc1 As Word.Contentcontrols
Dim cc2 As Word.Contentcontrols
Dim cc As Word.ContentControl

Set doc = ActiveDocument
Set cc1 = doc.SelectContentControlsByTitle("Name1")
For Each cc In cc1
cc.XMLMapping.SetMapping "/tree", , doc.CustomXMLParts.SelectByID
(doc.Variables("Xml1"))
Next
Set cc2 = doc.SelectContentControlsByTitle("Name2")
For Each cc In cc2
cc.XMLMapping.SetMapping "/flower", , doc.CustomXMLParts.SelectByID
(doc.Variables("Xml2"))
Next

End Sub
 
R

Rich Denis

Cindy,

Thanks for the push in the right direction. You were correct. Jie's
solution did not work as I would have hoped since it establishes a hard link
to the document. I did take your advise on the custom xml node. I am using
the 2007 Content Control Toolkit to do the mapping and now new docs work as
you described.

Thanks so much.
 

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