Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 12-13-2012, 05:45 PM
gmaxey gmaxey is offline Cross Reference to Content Control Windows 7 32bit Cross Reference to Content Control Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Brent,

The following (very little error handling) should suffice for most simple mapping requirements. Just add titled CCs in your document and run the code. Copy and paste any titled CC to a new location and it is automatically mapped to the data node (and all other like titled CCs).

Code:
Sub MapAColectionOfCustomXMLParts()
Dim oCCs As New Collection
Dim oCXPart As CustomXMLPart
Dim oCC As ContentControl
Dim lngIndex As Long
Dim strTitle As String
  'Create a fresh CustomXMLPart for mapping.
  On Error Resume Next
  'Kill any existing CustomXMLPart used previously.
  Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace _
               ("http//mapCCcollection@namespace.com").Item(1)
  If Err.Number = 0 Then
    oCXPart.Delete
  End If
  On Error GoTo 0
  'Create the new CustomXMLPart.
  ActiveDocument.CustomXMLParts.Add _
                ("<CC_Collection xmlns='http//mapCCCollection@namespace.com'/>")
  Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace _
                ("http//mapCCCollection@namespace.com").Item(1)
 
  'Get unique titles.
  For Each oCC In ActiveDocument.ContentControls
    If oCC.Title <> "" Then
      On Error Resume Next
      oCCs.Add oCC, oCC.Title
    End If
  Next oCC
  On Error GoTo 0
 
  For lngIndex = 1 To oCCs.Count
    'Add a CustomXMLNode for eacj uniqued titled CC.
     Set oCC = oCCs(lngIndex)
     strTitle = Replace(oCC.Title, " ", "_")
     oCXPart.AddNode oCXPart.SelectSingleNode("ns0:CC_Collection"), _
                            strTitle, , , msoCustomXMLNodeElement
  Next lngIndex
  'Map titled CCs.
  For Each oCC In ActiveDocument.ContentControls
    If oCC.Title <> "" Then
      oCC.XMLMapping.SetMappingByNode oCXPart.SelectSingleNode("//" & Replace(oCC.Title, " ", "_") & "[1]")
    End If
  Next oCC
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross Reference to Content Control Need help with using bookmark and cross-reference mpdsal Word 1 07-26-2012 01:05 PM
Cross-reference problem Marineboy Word 2 08-05-2011 03:37 AM
Cross Reference to Content Control How to control the caption and their Cross-reference? Jamal NUMAN Word 1 04-10-2011 03:23 PM
2 figures cross reference mmdmov Word 0 05-05-2010 09:12 AM
How do I return from a cross reference? smoggymark Word 0 10-21-2008 07:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:41 AM.


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