![]() |
#1
|
|||
|
|||
![]()
Hello together,
I need some help. I'm just practicing with Word and XMLMapping and showing and hiding a text via checkboxes. Now I would like, if a checkbox is active, another checkbox should be hidden. Can someone help me with an example how I can realize this. Many greetings George |
#2
|
|||
|
|||
![]()
George,
You haven't tried very hard. Less than ten post down from your post in this forum is content on this topic: https://www.msofficeforums.com/word-...-document.html |
#3
|
|||
|
|||
![]()
Many thanks for the information. After a long search and many failed attempts I have taken the easier way.
I have one more question. Is there an elegant way to hide all checkboxes? The goal should be that the worksheet can be printed without checkboxes. It would also be sufficient to have a "master checkbox" that hides all other checkboxes. |
#4
|
|||
|
|||
![]()
This is a Word forum and in Word there are no worksheets. What code have you already used?
|
#5
|
|||
|
|||
![]()
Hello Greg,
please excuse me, but I had already meant Word. I looked at the link from you and the checkboxes work great. As I understand the program, the hiding and showing of checkboxes works when I am in the "Result" environment. What if the checkboxes are freely distributed in the document? Does it still work then? Is it even possible with a "master" checkbox to hide all subsequent checkboxes using VBA and XMLmapping? I have attached a possible scenario once with "Section 1". which would help me even if, when I print, all checkboxes are not in the document. The focus is only on the checkboxes and not on all other controls. |
#6
|
|||
|
|||
![]() Code:
Option Explicit Private WithEvents oCXPart As CustomXMLPart Private Sub Document_Open() Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace("http://TheAnchorage.com").Item(1) 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. 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 |
#7
|
|||
|
|||
![]()
thank you very much for your help. i first have to deal with this code to understand it.
you have helped me so far and i don't dare to ask you if you would mind if you could upload this code with a Word document? |
#8
|
|||
|
|||
![]()
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 |
#9
|
|||
|
|||
![]() Quote:
|
#10
|
|||
|
|||
![]()
problem solved
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Toggle Collapse/Expand via Content Control Checkbox | metaflowdesigns | Word VBA | 5 | 07-08-2020 02:53 PM |
![]() |
namrehx | Word VBA | 16 | 12-14-2017 01:45 PM |
Hide rows with checkbox | gebobs | Excel | 3 | 03-24-2015 12:05 PM |
![]() |
vinceplunkett | Word | 1 | 12-03-2013 01:53 AM |
![]() |
mutchy25 | PowerPoint | 1 | 09-21-2012 01:40 AM |