3 mai 2012 23:11
Our operations team frequently (each person several times per day) writes letters that follow a specific format (boilerplate). Although the boilerplate is the same on each letter, there are actually 20 different versions of the letter template, each on a different letterhead.
For years, the operations team used letters that I created in Word 2003 using legacy control form fields.
Several months ago, I re-created these letters using Word 2007 Content Controls. With the new content controls and the Word 2007 Content Control Toolkit from Codeplex, I was able to join Content Controls that are intended to contain the same content, which helps reduce mismatches when users neglect to proofread their letters carefully.
We recently developed a solution that pre-fills some of the Controls Controls from data in our database, saving users time and reducing copying errors. Development and adoption has been going very well until today.
This week I released a version of the boilerplate letter on a new letterhead. This is still the version where users have to fill in the content controls manually.
A user called me to his desk and demonstrated this:
- He entered content into several content controls.
- He saved and closed the document.
- When he reopened the document, the content controls were empty.
After doing some research and some exploring, I figured out that there were four items in the customXml layer instead of the usual one. item 4.xml is the bibliography layer, so I'm not too worried about it. The data that the user entered is stored in item3.xml, but the document is displaying item1.xml or item2.xml, which contain only empty tags.
As I said, we have been using this technology for months and nobody has complained about this before.
The difference between the other letters and this one is this:
- all the other letters are saved as Word documents (.docx) or Word Macro-enabled documents (.docm). I used the Windows file properties control to make these documents read-only so that the masters stay clean.
- this new letter is on a storage device that will not let me make it read-only, so I saved this version as a Word template (.dotx), again so that the master stays clean.
So, my questions are:
- Why does the template (.dotx) have multiple items in the customXml layer?
- Why is Word saving the data to one item in the customXml layer and then displaying a different item?
- How do I get Word to display the content layer that I care about?
An unrelated issue: The default text inside the content controls is grey, which makes it easier to find the content controls that need to be filled in. Most of the time, but not always, the text in the content control turns black when data is entered. Why is it that it sometimes stays grey when content is entered? How do I force it to turn black?
4 mai 2012 06:26
It sounds as if, somehow, the content controls have been mapped to the wrong custom xml part. I'm not intimately familiar with how the Custom UI Editor works - I usually handle the content control mappings with my own code. I did play with it once, but found some of its workings a bit odd, so stuck with my own methods. I vaguely recall that there are some actions that will end up generating multiple custom xml parts and that this is one of the reasons I didn't care to work with it.
I guess I'd delete all the custom XML parts from this template (but not the content controls), open it again in the Editor and recreate the links, being careful to not let the tool generate more than one custom xml part.
I usually delete Custom XML Parts from a document using the following steps:
- Press Alt+F11 to open the VBA Editor; press Ctrl+G to open the Immedite window
- In the Immediate window, type: ?ActiveDocument.CustomXMLParts.Count
Press Enter. This tells you how many Custom XML Parts are present. By default in a new document there will be at least three for document properties.
- In the Immediate window, type: ?ActiveDocument.CustomXMLParts([index]).XML
Press Enter. [index] = 1 to the result of the Count query. Substitute each value in turn and press Enter. This way you can determine what XML is in each Custom XML Part. Determine which parts are "extraneous".
- In the Immediate window, type: ActiveDocument.CustomXMLParts([index]).Delete
Press Enter. Here, [index] is the value of each Custom XML Part that you want to remove; repeat as often as required for the parts you want to remove.
<<An unrelated issue: The default text inside the content controls is grey, which makes it easier to find the content controls that need to be filled in. Most of the time, but not always, the text in the content control turns black when data is entered. Why is it that it sometimes stays grey when content is entered? How do I force it to turn black?>>
There could be a couple of reasons for this. The one that immediately comes to mind is that the control has been formatted with that color, or a style that applies that color. What happens if you select the text and apply a different color to it?
Cindy Meister, VSTO/Word MVP
4 mai 2012 17:33
Thanks for the suggestion, Cindy.
I tried moving the master letter template to a different storage device and then used the read-only trick (save as .docx then apply Windows property) that worked for the other masters, but that didn't help.
This morning I did a little more checking and found that the master letter template had the four customXml layers, so I'm thinking the source of the problem is there. I tried to delete all but one of the customXML items using Visual Studio, but that broke the document archive.
I was able to delete the extra items successfully using the Word 2007 Content Control Toolkit and initial testing looks good.
On the unrelated text color issue, two content controls in the same paragraph (and with the same style applied) can behave differently with one turning black when data is entered and the other one staying grey. This seems to be a much bigger problem in Word 2007 (the majority of users) and a rare problem in Word 2010 (like myself).
5 mai 2012 08:47
<<On the unrelated text color issue, two content controls in the same paragraph (and with the same style applied) can behave differently with one turning black when data is entered and the other one staying grey. This seems to be a much bigger problem in Word 2007 (the majority of users) and a rare problem in Word 2010 (like myself).>>
I've never encountered this. As it's an end-user issue and not a programming question, you might try asking on the Answers site. Possibly, someone there has encountered it and knows where it comes from and if there's any recourse or if it's a bug in the older version. I do find a couple of other discussions in a Google search that report something similar, with no resolution however.
Cindy Meister, VSTO/Word MVP