How to access Checkbox from VBA in Excel 2007

前端 未结 3 1898
暗喜
暗喜 2021-01-12 14:19

When adding a checkbox, how do you access the value from VBA?

  • In Excel 2007, on the Developer Ribbon
  • Insert, Form Controls, Checkbox
  • Rena
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 15:09

    One way:

    Dim oCheck As Object
    Set oCheck = Sheet1.CheckBoxes("chkMyCheck")
    MsgBox (oCheck.Value = xlOn)
    

    Edit: here's another method - maybe this one will work for you...

    Sub Tester2()
        Dim sh As Shape
        For Each sh In Sheet1.Shapes
            If sh.Type = msoFormControl Then
                If sh.FormControlType = xlCheckBox Then
                     Debug.Print sh.Name & "=" & sh.ControlFormat.Value
                End If
            End If
        Next sh
    End Sub
    

提交回复
热议问题