Excel VBA脚本清除列中的所有复选框

我正在尝试清除特定单元格区域中的所有活动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

最佳答案 尝试使用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
点赞