Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 11-20-2012, 02:59 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,439
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You don't really have to have a Node named for every CC title you want to map, you just need a node (see above.) If you do want a node name to match the CC name then:

HTML Code:
Sub MapCCs()
Dim oCC As Word.ContentControl
Dim oCustomPart As Office.CustomXMLPart
Dim oDoc As Word.Document
Dim lngIndex As Long
Dim oNode As CustomXMLNode
  Set oDoc = ActiveDocument
  ClearXMLParts
  Set oCustomPart = oDoc.CustomXMLParts.Add("<?xml version='1.0' encoding='utf-8'?><Root_Node></Root_Node>")
  For lngIndex = 1 To oDoc.ContentControls.Count
    Set oCC = oDoc.ContentControls(lngIndex)
    Select Case oCC.Title
      Case "Name"
        Set oNode = oCustomPart.SelectSingleNode("/Name")
        If oNode Is Nothing Then
          oCustomPart.AddNode oCustomPart.SelectSingleNode("/Root_Node"), "Name"
        End If
        
        oCC.XMLMapping.SetMapping "/Root_Node/Name[1]", , oCustomPart
      Case "Address"
        Set oNode = oCustomPart.SelectSingleNode("/Address")
        If oNode Is Nothing Then
          oCustomPart.AddNode oCustomPart.SelectSingleNode("/Root_Node"), "Address"
        End If
       
        oCC.XMLMapping.SetMapping "/Root_Node/Address[1]", , oCustomPart
      Case "Age"
        Set oNode = oCustomPart.SelectSingleNode("/Age")
        If oNode Is Nothing Then
          oCustomPart.AddNode oCustomPart.SelectSingleNode("/Root_Node"), "Age"
        End If
        oCC.XMLMapping.SetMapping "/Root_Node/Age[1]", , 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
  #17  
Old 11-20-2012, 03:25 PM
RobsterCraw RobsterCraw 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 32bit
Novice
Creating a plain text content control for every instance of a word or phrase
 
Join Date: Nov 2012
Posts: 11
RobsterCraw is on a distinguished road
Default

Excellent, thank you. You've answered the original matter of my question and then some. I am going to keep working on this, but I'm out of time today.
Reply With Quote
Reply

Tags
content control, find & replace, xml



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 05:49 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