读书人

动态内容控件运用(一)

发布时间: 2013-01-28 11:49:56 作者: rapoo

动态内容控件应用(一)
例程目的:

在一个表格中,当选择"None"前的CheckBox后,表格中的其他CheckBox会消失(以防错选)。当取消选择后CheckBox会重新出现。如图:

动态内容控件运用(一)动态内容控件运用(一)

说明:此前必须将"None"前CheckBox的Title设定为"None"。

Option ExplicitPrivate 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 IfEnd Sub


读书人网 >其他相关

热点推荐