I created a Word Document (Word 2016) that, by clicking a button, generates a Table with predefined text and formatting.
Column1 | Column2 | Column3 |
---|---|---|
QUESTION (Y/N) | YES_Checkbox | No_Checkbox |
Row number 8 (shown above) contains a YES/NO question; to manage that, I inserted two Checkboxes (one in Column2, the other in Column3) using the following syntax:
For ii = 2 To 3
Set rng = mytable.Cell(8, ii).Range
rng.Select
With Selection
.Collapse Direction:=wdCollapseStart
.Range.ContentControls.Add wdContentControlCheckBox
.MoveRight Unit:=wdCharacter, Count:=2
End With
Next ii
My idea is to have mutually exclusive checkboxes: that means, if User selects "YES" the "NO" is automatically deselected (and vice-versa). To do so, I created a Sub within the main button script. It checks for the checkbox value and then tries to 'tick it' (on un-tick it) using the following code (not yet completed):
Sub Check_YES_Not(tblNew)
Dim thisCell As Range
check1 = mytable.Cell(8, 2).Range.ContentControls(1).Checked
check2 = mytable.Cell(8, 3).Range.ContentControls(1).Checked
'If condition to be added
check1 = True 'This is how I am trying to modify the checkbox, but it is not working
'ElseIf add other conditions...
'Msgbox "to be completed..."
'End If
End Sub
Code runs and creates the table correctly, but the checkbox scripts is not behaving as I wish. Could someone please tell me what I am doing wrong and how I could make it work? Thank you very much.
Aucun commentaire:
Enregistrer un commentaire