Home > Mobile >  Getting the 'content' from a Rich Text Content Control
Getting the 'content' from a Rich Text Content Control

Time:06-22

I need to get the 'contents' of a Rich Text Content Control in Word, and paste that content into another Rich Text Content Control (formatted).

Here's the code I have:

ActiveDocument.SelectContentControlsByTitle("original").Item(1).Range.FormattedText.Copy
ActiveDocument.SelectContentControlsByTitle("duplicate").Item(1).Range.Paste

Which seems to work, but it's copying the entire original ContentControl into (nested) the duplicate ContentControl... and I just want the formatted text alone.

original and duplicate content which is nested

enter image description here

CodePudding user response:

Try:

With ActiveDocument
  .SelectContentControlsByTitle("duplicate")(1).Range.FormattedText = _
  .SelectContentControlsByTitle("original")(1).Range.FormattedText
End With

CodePudding user response:

Rather than use vba for this, Map the Content Controls.

For Rich Text controls, you will need to map the XML parts.

Data Mapping

The real power of content controls lies in their ability to be mapped (or bound) to a custom XML data store embedded in the Word 2007/2010 OfficeOpenXML format document file. Through this binding:

  • Any changes in the data store data is automatically repeated in all content controls mapped to that data.
  • Any changes to a mapped content control automatically updates the data store and all other content controls mapped to that data store data.

Word Content Controls by Greg Maxey

While you can do this yourself, why? There are a number of free tools that will do it for you.

I am sure there are more out there but I have used the above tools. They have different interfaces and powers but all of them give you the ability to add a Mapped Content Control to a document, including a Rich Text one.

  • Related