动态内容控件应用(一)
例程目的:
在一个表格中,当选择"None"前的CheckBox后,表格中的其他CheckBox会消失(以防错选)。当取消选择后CheckBox会重新出现。如图:
说明:此前必须将"None"前CheckBox的Title设定为"None"。
Option Explicit Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl) Dim r, c As Integer Dim Cel As Word.range Dim t As String If ContentControl.Title = "None" And ContentControl.Checked Then For r = 1 To ActiveDocument.Tables(1).Rows.Count For c = 1 To ActiveDocument.Tables(1).Columns.Count Set Cel = ActiveDocument.Tables(1).Cell(r, c).range If Cel.ContentControls(1).Title <> "None" Then Cel.ContentControls(1).LockContentControl = False Cel.ContentControls(1).Delete (True) End If Next Next ElseIf ContentControl.Title = "None" And Not ContentControl.Checked Then For r = 1 To ActiveDocument.Tables(1).Rows.Count For c = 1 To ActiveDocument.Tables(1).Columns.Count Set Cel = ActiveDocument.Tables(1).Cell(r, c).range t = Replace(Cel.Text, Chr(13), "") If Cel.ContentControls.Count = 0 Then Cel.Select Application.Selection.range.ContentControls.Add wdContentControlCheckBox Application.Selection.MoveRight Unit:=wdCharacter, Count:=2 Application.Selection.range.Text = t End If Next Next End If End Sub
征诛志异,三让两家王朝;功同开辟,一桮万古江南。