#1
|
|||
|
|||
Mapped Content Controls in Building Blocks?
Split from this thread.
Quote:
The Document Property Content Controls under the Quick Parts, do, but they are limited. Repeating Data Using Document Property Content Controls and Other Mapped Content Controls Last edited by Charles Kenyon; 05-20-2021 at 07:31 PM. Reason: Link back to original thread |
#2
|
||||
|
||||
Charles
I haven't had a problem keeping mapped CCs working after retrieving from Building Blocks so there isn't an underlying issue there that I'm aware of. I can post a sample template if you want to test it on your machine.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Andrew,
Please do. I just tried it again.
Here is a sample template that has two building blocks, one AutoText and on Quick Part. Both were created with mapped CCs that worked as such in the original document. Load as a global/add-in. When inserted, neither inserts a mapped CC. It does insert the CCs. |
#4
|
||||
|
||||
Charles
Your workflow is flawed. The mapped CCs are still mapped but you are putting them into a document that doesn't contain the necessary xml file. If you created the template with the xml file then you could create new documents FROM THAT TEMPLATE which already contain the xml. If you want this as a global template then you also need code to insert the xml file into a document so that the mapped CCs can link to that metadata. Ideally that xml file will already be sitting in the document BEFORE you insert the building block, as it would avoid the confusion you have with two CCs containing different data but you can add it after the event as well.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
Charles
Here is a demonstration of the principle. Note that the template itself contains the embedded xml already so the building blocks inserted all link to that data. If you create new documents from this template then they also contain the xml file which can be modified by virtue of the link to a CC on the page. If you use this template as an addin, the document you want to insert the building blocks into must ALSO have the xml embedded but this is a secondary step that needs to be taken. You could use a docx which contains the xml as your 'template' for new documents if you really wanted to keep the building blocks in a global template. This is the reasoning of why I suggested the OP would do a SaveAs for each of the subsequent docs - each new document already contains the populated metadata in an embedded xml file. And in the case of the template you put in post 3, you could inject the following xml file into a legacy document to allow the CC to find its value mapped to the CC1 field. <CC_Map_Root xmlns="http://Greg_Maxey/CC_Mapping_Part"><mapNode_1></mapNode_1><mapNode_2></mapNode_2><mapNode_3></mapNode_3><mapParentNode_1><nestedMapNode_1></nestedMapNode_1><nestedMapNode_2></nestedMapNode_2></mapParentNode_1><CC1>This is big a test</CC1></CC_Map_Root>
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
I am aiming for a Global Template where the mapped controls can be inserted into any new document, not based on a particular template or pre-built with additional XML. I am looking at being able to do this entirely within the Word interface once it is set up with no additional work in XML.
See the attached template, which when used as a Global Template, allows insertion of the mapped content controls into any document. Again, these are repurposed Document Property Content Controls. (I may make additional changes to this. Here is a live link.) In thinking about this, it occurs to me that if the form developer's Normal Template were to contain the XML mapping of custom Content Controls, the mapping would be present in new documents. I can see the possibility of having an alternative blank development template that had the mapping being used. It would also have the building blocks and should work much the same without being limited to the document property content controls. One would start new templates based on that blank for distribution. I think this is along the lines you are talking about without having to do any XML modification of new documents. That template could also be shared. (P.S. I still like using mail merge for this, though. I am referring back to the original question.) |
#7
|
||||
|
||||
Including the xml in the Normal.dotm is not a good idea for all the same reasons we avoid doing things to that template. It might work for the developer but only for new documents that they create - not for legacy docs, nor for anyone else creating documents.
Doing this with a global template is overthinking the problem. We can use a simple attached dotx template. Going to a global template introduces a series of problems which need to be solved by macros - hence moving to dotm. If you want to insert building blocks with mapped CCs to existing documents you need to make sure the page setup and style definition match as well as worrying about the xml. If you want to do it the hard way with global templates then use a macro which checks to see if the xml is already there and if not, creates it. In your template you used Greg Maxey's tool to create the xml from the CC titles. If you then run that same code on a legacy document you inserted the building block into, you will recreate the xml that the CCs need. If you wanted to avoid Greg's tool, you could include code in your global template to ensure the xml exists. Something like this would work to create the necessary fields. Note that it will wipe any existing data already in CCs so it would be better to run it before the user has populated them. If you decided to retain the xml file if it already exists, for completeness you should also check each individual field is already there as well. Code:
Sub TestAddCustomPart() AddCustomPart End Sub Function AddCustomPart(Optional sNS As String) As Office.CustomXMLPart 'Replaces/Creates the standard CustomXmlPart Dim oXMLPart As Office.CustomXMLPart, sXML As String Dim arrElements() As String, iElement As Integer, sFields As String If sNS = "" Then sNS = csNamespace For Each oXMLPart In ActiveDocument.CustomXMLParts 'Debug.Print oXMLPart.NamespaceURI 'oXMLPart.Xml If oXMLPart.NamespaceURI = sNS Then Debug.Print oXMLPart.XML oXMLPart.Delete '---- or exit the macro because it already exists ---- End If Next sFields = "ProjectID,ProjectName,ProjectNameShort,ProjectPhase,ContractNumber,ContractName,Client,VolumeNumber,VolumeName,DocumentID,DataItemNumber,DocumentTitle" arrElements = Split(sFields, ",") For iElement = LBound(arrElements) To UBound(arrElements) sXML = sXML & " <" & arrElements(iElement) & " />" & vbCr Next iElement sXML = "<?xml version='1.0' encoding='utf-8'?>" & vbCr & "<Root xmlns='" & sNS & "'>" & vbCr & sXML & "</Root>" Set AddCustomPart = ActiveDocument.CustomXMLParts.Add(sXML) Debug.Print AddCustomPart.XML End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Formatting in mapped controls replicated | jthomas666 | Word | 3 | 10-10-2019 11:03 AM |
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks | jc491 | Word VBA | 7 | 01-03-2016 10:34 PM |
UserForm to Add XML Mapped Content Controls | DocTeam10 | Word VBA | 0 | 10-08-2015 08:27 AM |
Building blocks show correctly in dropdown, but wrong building block populates in doc | wordgirl123 | Word | 0 | 10-03-2013 08:30 AM |
how to use Building Blocks or controls to add a page | verbster | Word | 11 | 03-06-2011 04:05 PM |