Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #14  
Old 11-20-2012, 02:43 PM
gmaxey gmaxey is offline Creating a plain text content control for every instance of a word or phrase Windows 7 32bit Creating a plain text content control for every instance of a word or phrase Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,652
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Lets try to simplify this a little. Add three CCs to a document. Named "Name", "Address", and "Age".

Copy and pastes the three CCs to various other places in the document. So now you have two or three CCs named "Name" and four or five named "Address" and so on.

You want to map all the CCs named "Name" to one XML node, all named "Address" to another XML node and so on.

HTML Code:
Option Explicit
Sub XXXAddContentControlAndMapToLocalXML()
Dim oCC As Word.ContentControl
Dim oCustomPart As Office.CustomXMLPart
Dim xmlPart As String
Dim oDoc As Word.Document
Dim lngIndex As Long
Dim bTitled As Boolean
  Set oDoc = ActiveDocument
  bTitled = False
  ClearXMLParts
  'Create the basic XML Part
  xmlPart = "<?xml version='1.0' encoding='utf-8'?><Root_Node><CCMapping_Node></CCMapping_Node></Root_Node>"
  Set oCustomPart = oDoc.CustomXMLParts.Add(xmlPart)
  'Add two more "CCMapping_Node" nodes.
  For lngIndex = 1 To 2
    oCustomPart.AddNode oCustomPart.SelectSingleNode("/Root_Node"), "CCMapping_Node"
  Next lngIndex
  For lngIndex = 1 To oDoc.ContentControls.Count
    Set oCC = oDoc.ContentControls(lngIndex)
    Select Case oCC.Title
      Case "Name"
        'Map all CCs titled "Name" to CCMapping_Node node 1.
        oCC.XMLMapping.SetMapping "/Root_Node/CCMapping_Node[1]", , oCustomPart
      Case "Address"
        'Map all CCs titled "Address" to CCMapping_Node node 2.
        oCC.XMLMapping.SetMapping "/Root_Node/CCMapping_Node[2]", , oCustomPart
      Case "Age"
        'Map all CCs titled "Age" to CCMapping_Node node 3.
        oCC.XMLMapping.SetMapping "/Root_Node/CCMapping_Node[3]", , oCustomPart
    End Select
  Next lngIndex
End Sub
'Run ClearXMLParts prior to testing these examples.
Sub ClearXMLParts()
Dim lngIndex As Long
'MsgBox ActiveDocument.CustomXMLParts.Count
For lngIndex = ActiveDocument.CustomXMLParts.Count To 4 Step -1
  ActiveDocument.CustomXMLParts(lngIndex).Delete
Next lngIndex
End Sub
 
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

Tags
content control, find & replace, xml

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a plain text content control for every instance of a word or phrase Rich text/Plain text Content Controls in Template michael.fisher5 Word 9 11-19-2014 06:36 AM
Creating a plain text content control for every instance of a word or phrase How do you set rich text in a content control Testor Word VBA 4 07-08-2012 07:55 AM
Word2010 check boxes and plain text content control boxes in same table fcsungard Word 5 06-01-2012 01:16 AM
Creating a plain text content control for every instance of a word or phrase Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:23 PM.


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