[英]Excel VBA script clear all checkboxes in column
I'm trying to clear all active X check boxes in a specific range of cells, or by column 我正在尝试清除特定范围的单元格或按列中的所有活动X复选框
It seems like it would be simple as I was able to do it for the entire worksheet with the below code. 看起来很简单,因为我可以使用以下代码在整个工作表中做到这一点。 I'm just not sure how to modify this to only apply for the single column or range of cells.
我只是不确定如何修改它以仅适用于单列或单元格范围。
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
Try using the topleftcell
property: 尝试使用
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
Obj.TopLeftCell.Column
会告诉您该复选框位于哪一列。基于此,您可以决定是否要更改其值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.