View Single Post
 
Old 06-07-2020, 07:50 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

Paul, how is the container remaining in the document anymore egregious than leaving a bookmark in the document? The idea is to leverage the customXMLPart and its events. However, I take your point, it is over complicated to nest a DDL in a rich text CC.

As a demonstration of concept, I've modified the attached to add a plain text and DDL which is dependent on a master DDL selection.


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_DDL As ContentControl, oCC_PT As ContentControl
  Set oCC_DDL = ActiveDocument.SelectContentControlsByTag("DepDDL").Item(1)
  Set oCC_PT = ActiveDocument.SelectContentControlsByTag("fixText").Item(1)
  If bDeadNode Then
    With oCC_DDL
      .LockContents = False
      .Type = 1
      .Range.Text = vbNullString
      .SetPlaceholderText , , ChrW(8203)
      .LockContents = True
    End With
     With oCC_PT
      .LockContents = False
      .Range.Text = vbNullString
      .LockContents = True
    End With
  Else
    If oNodePassed.ParentNode.BaseName = "Question" Then
      Select Case oNodePassed.Text
        Case Is = "Yes"
          With oCC_DDL
            .SetPlaceholderText , , "Choose item"
            .Type = 4
            .LockContents = False
            .Range.Select
          End With
          With oCC_PT
           .LockContents = False
           .Range.Text = "Please select from menu:"
           .LockContents = True
         End With
        Case Else
          With oCC_DDL
            .LockContents = False
            .Type = 1
            .Range.Text = vbNullString
            .SetPlaceholderText , , ChrW(8203)
            .LockContents = True
          End With
          With oCC_PT
           .LockContents = False
           .Range.Text = vbNullString
           .LockContents = True
         End With
      End Select
    End If
  End If
lbl_Exit:
  Exit Sub
End Sub
Attached Files
File Type: docm Linked text using CustomXMLPart events.docm (39.5 KB, 13 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote