Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 06-07-2020, 07:50 AM
gmaxey gmaxey is offline Absolute Dependent Dropdown lists Windows 10 Absolute Dependent Dropdown lists 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
 

Tags
#dropdown#dependent



Similar Threads
Thread Thread Starter Forum Replies Last Post
Absolute Dependent Dropdown lists Content Controls - Dependent Dropdown someazguy Word VBA 14 02-05-2023 08:01 PM
Absolute Dependent Dropdown lists Multiple dependent dropdown lists in table with add new row option jeweldarby Word VBA 6 05-21-2022 04:37 PM
Absolute Dependent Dropdown lists Dependent dropdown and repeat section NLJ Word VBA 3 01-12-2020 05:00 PM
Dropdown dependent text JakeLRL Word VBA 7 04-07-2016 08:26 AM
Dependent drop down lists bobbych Word 1 02-08-2013 04:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:47 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