여기에 체크 박스를 계산하거나 테이블에서 체크 박스를 확인하는 방법에 대한 몇 가지 예를의 ContentControls
개체를 반환하고 그것을
을 악용하는 Range
개체의 ContentControls
속성을 사용하거나 단일 열에서 :
Option Explicit
Sub main()
With ActiveDocument
MsgBox CountCheckBoxes(.Tables(1)) & " CheckBox instances were found"
MsgBox CountCheckedCheckBoxes(.Tables(1)) & " checked CheckBox instances were found"
MsgBox CountCheckBoxesInColumn(.Tables(1), 1) & " CheckBox instances were found in column 1"
MsgBox CountCheckedCheckBoxesInColumn(.Tables(1), 1) & " checked CheckBox instances were found in column 1"
End With
End Sub
Private Function CountCheckBoxes(table As table, Optional col As Variant) As Long
Dim cc As ContentControl
With table
For Each cc In .Range.ContentControls
If cc.Type = wdContentControlCheckBox Then CountCheckBoxes = CountCheckBoxes + 1
Next cc
End With
End Function
Private Function CountCheckedCheckBoxes(table As table) As Long
Dim cc As ContentControl
With table
For Each cc In .Range.ContentControls
If cc.Type = wdContentControlCheckBox Then If cc.Checked Then CountCheckedCheckBoxes = CountCheckedCheckBoxes + 1
Next cc
End With
End Function
Private Function CountCheckBoxesInColumn(table As table, col As Long) As Long
Dim i As Long
With table
For i = 1 To .Rows.count
CountCheckBoxesInColumn = CountCheckBoxesInColumn + .Cell(i, col).Range.ContentControls.count
Next i
End With
End Function
Private Function CountCheckedCheckBoxesInColumn(table As table, col As Long) As Long
Dim i As Long
With table
For i = 1 To .Rows.count
CountCheckedCheckBoxesInColumn = CountCheckedCheckBoxesInColumn + CountCheckBoxesCheked(.Cell(i, col).Range)
Next i
End With
End Function
Function CountCheckBoxesCheked(rng As Range) As Long
Dim cc As ContentControl
With rng
For Each cc In .ContentControls
If cc.Type = wdContentControlCheckBox Then If cc.Checked Then CountCheckBoxesCheked = CountCheckBoxesCheked + 1
Next cc
End With
End Function
정말 대단합니다! 고마워요! – Snoopy
당신은 오신 것을 환영합니다. 그러면 내 대답을 수락 된 것으로 표시 할 수 있습니다. 고맙습니다 – user3598756