我正在尝试创建一个表单,该表单将使用我已添加书签的预先存在的文本填充文档。我已经多次尝试编写代码,但它一直在这一行显示错误:
If ActiveDocument.SelectContentControlsByTitle(checkboxName)(1).Checked = True Then
或
Set checkbox = ActiveDocument.SelectContentControlsByTitle(checkboxName)(1).CheckBox
Private Sub UpdateBookmarkVisibility(bookmarkName As String, checkboxName As String) 如果 ActiveDocument.SelectContentControlsByTitle(checkboxName)(1).Checked = True 那么 '隐藏书签 ActiveDocument.Bookmarks(bookmarkName).Range.Font.Hidden = True 别的 '显示书签 ActiveDocument.Bookmarks(bookmarkName).Range.Font.Hidden = False 万一 结束子
Private Sub UpdateAllBookmarks() UpdateBookmarkVisibility "I1", "CheckBox1" UpdateBookmarkVisibility "I2", "CheckBox2" UpdateBookmarkVisibility "I3", "CheckBox3" 结束子
私人子按钮1_Click() 更新所有书签 结束子
或
私有子 CheckBox1_Click() UpdateBookmarkVisibility "Bookmark1", "CheckBox1" 结束子
私有子 CheckBox2_Click() UpdateBookmarkVisibility "Bookmark2", "CheckBox2" 结束子
私有子 CheckBox3_Click() UpdateBookmarkVisibility "Bookmark3", "CheckBox3" 结束子
Private Sub UpdateBookmarkVisibility(bookmarkName As String, checkboxName As String) 将复选框变暗为复选框 设置复选框 = ActiveDocument.SelectContentControlsByTitle(checkboxName)(1).CheckBox
If checkbox.Value = True Then
' Hide the bookmark
ActiveDocument.Bookmarks(bookmarkName).Range.Font.Hidden = True
Else
' Show the bookmark
ActiveDocument.Bookmarks(bookmarkName).Range.Font.Hidden = False
End If
结束子