我试图清除特定单元格区域中的所有活动X复选框,或按列
看起来它很简单,因为我可以使用以下代码为整个工作表执行此操作。我只是不确定如何将其修改为仅适用于单列或单元格区域。
Sub ClearAllCheckboxes()
Dim Answer As String
Dim MyNote As String
Dim Obj As Object
MyNote = "This will Clear all CheckBoxes Proceed? "
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???")
If Answer = vbNo Then
Exit Sub
Else
On Error Resume Next
For Each Obj In ActiveSheet.OLEObjects
Obj.Object.Value = False
Next Obj
End If
End Sub
答案 0 :(得分:1)
尝试使用topleftcell
属性:
Sub ClearAllCheckboxes()
Dim Answer As String
Dim MyNote As String
Dim Obj As Object
dim rg as range
set rg=selection
MyNote = "This will Clear all CheckBoxes Proceed? "
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???")
If Answer = vbNo Then
Exit Sub
Else
On Error Resume Next
For Each Obj In ActiveSheet.OLEObjects
if not intersect(rg, obj.topleftcell) is nothing then _
Obj.Object.Value = False
Next Obj
End If
End Sub
答案 1 :(得分:1)
Obj.TopLeftCell.Column
会告诉您复选框所在的列。基于此,您可以决定是否要更改其值。