Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2021, 03:53 PM
Charles Kenyon Charles Kenyon is offline Mapped Content Controls in Building Blocks? Windows 10 Mapped Content Controls in Building Blocks? Office 2019
Moderator
Mapped Content Controls in Building Blocks?
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Question Mapped Content Controls in Building Blocks?

Split from this thread.



Quote:
Originally Posted by Guessed View Post
I would recommend you explore mapped Content Controls with an xml file.

If the fields are all populated in one place (same as a Mail Merge) then you could use that to create an xml file which then populates the contract docs as required. I would probably create a single template which contained all the suite of documents as building blocks. Each of those building blocks would include mapped CCs where relevant. Then as a user, you would create a new document, either replace the xml file or perhaps have an 'all fields' version for you to populate the XML fields which you do to fully populate the xml. Then for each different contract doc you can:
1. SaveAs to create a new doc
2. Select all and delete the content
3. Insert the Building Block you want - the fields will be already filled.
My experience has been that mapped Content Controls do not survive as mapped in Building Blocks. Maybe I have been doing it wrong.

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
Reply With Quote
  #2  
Old 05-20-2021, 04:06 PM
Guessed's Avatar
Guessed Guessed is offline Mapped Content Controls in Building Blocks? Windows 10 Mapped Content Controls in Building Blocks? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 05-20-2021, 06:14 PM
Charles Kenyon Charles Kenyon is offline Mapped Content Controls in Building Blocks? Windows 10 Mapped Content Controls in Building Blocks? Office 2019
Moderator
Mapped Content Controls in Building Blocks?
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Andrew,
Please do.

I just tried it again.
  1. Created a Mapped plain text control.
  2. Saved it as a QuickPart in a template.
  3. Loaded the template as a global template.
  4. Inserted the content control from quick parts.
  5. Copied it to another place in the document.
  6. Made a change.
  7. The change was not reflected in the original.

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.
Attached Files
File Type: dotx 2021-05-20.dotx (61.5 KB, 6 views)
Reply With Quote
  #4  
Old 05-20-2021, 08:13 PM
Guessed's Avatar
Guessed Guessed is offline Mapped Content Controls in Building Blocks? Windows 10 Mapped Content Controls in Building Blocks? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 05-20-2021, 08:31 PM
Guessed's Avatar
Guessed Guessed is offline Mapped Content Controls in Building Blocks? Windows 10 Mapped Content Controls in Building Blocks? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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>
Attached Files
File Type: dotx Mapped Content Control Demonstration.dotx (37.6 KB, 7 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #6  
Old 05-21-2021, 07:00 AM
Charles Kenyon Charles Kenyon is offline Mapped Content Controls in Building Blocks? Windows 10 Mapped Content Controls in Building Blocks? Office 2019
Moderator
Mapped Content Controls in Building Blocks?
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.)
Attached Files
File Type: dotx DocProperty Building Blocks.dotx (141.8 KB, 6 views)
Reply With Quote
  #7  
Old 05-21-2021, 05:40 PM
Guessed's Avatar
Guessed Guessed is offline Mapped Content Controls in Building Blocks? Windows 10 Mapped Content Controls in Building Blocks? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
And looking back at the original question, I STILL think that mail merge filtered to a single record for 30 different documents is not a better solution. But I do recognise that if you increase the complexity of the solution (like insisting on global templates), mail merge may indeed become the best method.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mapped Content Controls in Building Blocks? 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
Mapped Content Controls in Building Blocks? how to use Building Blocks or controls to add a page verbster Word 11 03-06-2011 04:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft