View Single Post
 
Old 11-19-2019, 09:59 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

If you wanted to look at a macro solution, the code that would remove your existing xml and introduce a new named xml file might look like the following. You could add to the sFields line to include more element names. Note that you will need to relink your existing CCs any time you change the namespace (the sNS value in this code).
Code:
Sub AddCustomPart()
  MsgBox fnCustomPart.XML, vbOKOnly, "Custom XML added"
End Sub

Function fnCustomPart() As Office.CustomXMLPart
  'Creates/Recreates the standard CustomXmlPart (and removes xml with blank namespaces)
  Dim arrElements() As String, iElement As Integer, sFields As String, sXML As String, sNS As String
  Dim oXMLPart As Office.CustomXMLPart
  
  sNS = "http://schema.usaf.gov/commandchange"
  
  For Each oXMLPart In ActiveDocument.CustomXMLParts
    If oXMLPart.NamespaceURI = sNS Or oXMLPart.NamespaceURI = "" Then
      Debug.Print oXMLPart.XML
      oXMLPart.Delete
    End If
  Next
  
  sFields = "chaplin|cot|cotr|guideon|icc|iccfn|iccr|narr|narrr|narrfn|occ|occfn|occr|po|pofn|poduty|por|sq_grp|vol|volr|formation"
  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 fnCustomPart = ActiveDocument.CustomXMLParts.Add(sXML)
  'Debug.Print AddCustomPart.XML
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote