我有一个模板 .dotm,其中有多个复选框内容控件。它们按如下方式分组:
[chk_1] Attach all the items listed below:
[chk_1_1] Item A
[chk_1_2] Item B
[chk_1_3] Item C
[chk_2] Send the details provided below:
[chk_2_1] Info A
[chk_2_2] Info B
[chk_2_3] Info C
我正在尝试做的是一种自动检查chk_1
是否检查了任何子项的方法,作为某种防故障系统,如果用户忘记手动检查chk_1
. 到目前为止,我已经设法手动执行此操作,如下所示:
Private Sub btnSubmit_Click()
Dim ctl As ContentControl
For Each ctl In ActiveDocument.ContentControls
If ctl.Type = wdContentControlCheckBox Then
If ctl.Tag = "chk_1_1" or ctl.Tag = "chk_1_2" or ctl.Tag = "chk_1_3" Then
If ctl.Checked = True Then
ActiveDocument.SelectContentControlsByTag("chk_1").Item(1).Checked = True
End If
End If
End If
Next
Dim ctl2 As ContentControl
For Each ctl2 In ActiveDocument.ContentControls
If ctl2.Type = wdContentControlCheckBox Then
If ctl2.Tag = "chk_2_1" or ctl2.Tag = "chk_2_2" or ctl2.Tag = "chk_2_3" Then
If ctl2.Checked = True Then
ActiveDocument.SelectContentControlsByTag("chk_2").Item(1).Checked = True
End If
End If
End If
Next
End Sub
此代码在单击 ActiveX 按钮时执行btnSubmit
,如果选中任何子复选框,则自动勾选父复选框。
我想简化代码,因为随着时间的推移,将会有多个组,每个组有 20 多个复选框,并且代码将更难编写。
有没有办法使用字符串或检查所有标记的复选框的状态chk_x_y
,然后修改状态chk_x
?