View Single Post
 
Old 11-17-2020, 06:52 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You really shouldn't need a document. You have one. Try:


Code:
Option Explicit
Private WithEvents oCXPart As CustomXMLPart
Private Sub Document_New()
  Document_Open
End Sub
Private Sub Document_Open()
  On Error GoTo Err_Part
  Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace("http://TheAnchorage.com").Item(1)
  On Error GoTo 0
  If Not ActiveDocument.SelectContentControlsByTitle("Checkbox_Master").Item(1).XMLMapping.IsMapped Then
    ActiveDocument.SelectContentControlsByTitle("Checkbox_Master").Item(1).XMLMapping.SetMapping "/ns0:CC_Map_Root[1]/ns0:CBM[1]", , oCXPart
  End If
lbl_Exit:
  Exit Sub
Err_Part:
  Set oCXPart = ActiveDocument.CustomXMLParts.Add("<?xml version='1.0'?><CC_Map_Root xmlns='http://TheAnchorage.com'><CBM/></CC_Map_Root>")
  Resume
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.
  If Not InUndoRedo Then 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)
  If Not InUndoRedo Then ProcessChange NewNode
lbl_Exit:
  Exit Sub
End Sub

Sub ProcessChange(oNodePassed As Office.CustomXMLNode, Optional bDeadNode As Boolean = False)
Dim oCC As ContentControl
Dim lngIndex As Long
  Select Case oNodePassed.ParentNode.BaseName
    Case "CBM"
      If oNodePassed.Text = "true" Then
        For lngIndex = 1 To 7
          ActiveDocument.SelectContentControlsByTitle("Checkbox" & lngIndex).Item(1).Range.Font.ColorIndex = wdAuto
        Next lngIndex
      Else
        For lngIndex = 1 To 7
          ActiveDocument.SelectContentControlsByTitle("Checkbox" & lngIndex).Item(1).Range.Font.ColorIndex = wdWhite
        Next lngIndex
      End If
  End Select
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote