知道选中了哪个复选框

时间:2013-09-09 11:41:21

标签: excel vba excel-vba

我的Excel表格中有这么多复选框。我在每个人的检查事件上都叫Common Sub。

是否可以知道在公共Sub中检查了哪个复选框? (所以我 可以采取相应的行动)

1 个答案:

答案 0 :(得分:1)

试试这个

Sub CommonClick
    Dim cb As CheckBox

    On Error Resume Next
    Set cb = ActiveSheet.Checkboxes(Application.Caller)
    If Err.Number <> 0 Then
        MsgBox "Sub not called from a CheckBox on current sheet"
        Exit Sub
    End If
    On Error GoTo 0

    MsgBox cb.Name & " was set to " & cb.Value
End Sub