View Single Post
 
Old 06-06-2020, 07:17 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You can actually make this relatively robust (if complicated) by mapping some CCs to a customXMLPart and playing a shell game with the node text:


In the attached I created a master Yes/No "Question" DDL, a rich text "Container" CC, a temporary Rich Text CC containing a dependent DDL and mapped them to a customXML part. I then added a null node to the CXP. Then I deleted the temporary rich text CC and dependent DDL.



Code:
Option Explicit
Dim WithEvents oCXPart As CustomXMLPart
Sub AutoOpen()
On Error Resume Next
  Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace("http://TheAnchorage.com/XMLPart").Item(1)
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterDelete(ByVal OldNode As Office.CustomXMLNode, ByVal OldParentNode As Office.CustomXMLNode, ByVal OldNextSibling As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when a #text node containing a value is replaced with Null value.
  If OldParentNode.BaseName = "Question" Then ProcessChange OldNode, True
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterInsert(ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when the Null value in a CXPart element node is replaced with a #text node containing a value.
  ProcessChange NewNode
lbl_Exit:
  Exit Sub
End Sub
Private Sub oCXPart_NodeAfterReplace(ByVal OldNode As Office.CustomXMLNode, ByVal NewNode As Office.CustomXMLNode, ByVal InUndoRedo As Boolean)
  'This event fires when the initial Null value in the node is replaced with a value.
  ProcessChange NewNode
lbl_Exit:
  Exit Sub
End Sub
Sub ProcessChange(oNodePassed As Office.CustomXMLNode, Optional bDeadNode As Boolean = False)
Dim oNode As CustomXMLNode
Dim oCC As ContentControl
  If bDeadNode Then
    oCXPart.DocumentElement.ChildNodes(4).Text = oCXPart.DocumentElement.ChildNodes(3).Text
  Else
    If oNodePassed.ParentNode.BaseName = "Question" Then
      Select Case oNodePassed.Text
        Case Is = "Yes"
          oCXPart.DocumentElement.ChildNodes(4).Text = oCXPart.DocumentElement.ChildNodes(2).Text
        Case Else
          oCXPart.DocumentElement.ChildNodes(4).Text = oCXPart.DocumentElement.ChildNodes(3).Text
      End Select
    End If
  End If
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote