excel vba - 检查单选按钮是否被选中?

标签 excel vba scripting

bt

我正在尝试检查这些简单单选按钮组的值,但我的语法已关闭,有人知道要更改什么吗? 注意:它们是 Excel 选项按钮而不是 ActiveX 按钮,并且不在用户窗体上。

 If Worksheets("Input").Shapes("Option Button 3").Select.Value = xlOn Then
     MsgBox "fir"
 ElseIf Worksheets("Input").Shapes("Option Button 4").Select.Value = xlOn Then
     MsgBox "sec"
 Else
     MsgBox "none" 'in case they were deleted off the sheet
 End If

最佳答案

试试这个

Sub ZX()
    Dim shp3 As Shape
    Dim shp4 As Shape

    On Error Resume Next
    Set shp3 = Worksheets("Input").Shapes("Option Button 3")
    Set shp4 = Worksheets("Input").Shapes("Option Button 4")
    On Error Goto 0 
    If shp3 Is Nothing Then
        If shp4 Is Nothing Then
            MsgBox "none" 'in case they were deleted off the sheet
        ElseIf shp4.ControlFormat.Value = xlOn Then
            MsgBox "sec"
        Else
            MsgBox "Only Button 4 exists and it is off"
        End If
    Else
        If shp3.ControlFormat.Value = xlOn Then
            MsgBox "fir"
        Else
            If shp4 Is Nothing Then
                MsgBox "Only Button 3 exists and it is off"
            ElseIf shp4.ControlFormat.Value = xlOn Then
                MsgBox "sec"
            Else
                MsgBox "Both exists, both are off"
            End If
        End If
    End If

End Sub

关于excel vba - 检查单选按钮是否被选中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7624631/

相关文章:

vba - 检查字符串格式

Excel VBA 如果单元格(x,J)。值(value)=值(value)

excel - 如何使每个单元格的长度为5?

excel - vba添加形状,等待3秒然后删除

java - 用 R 扩展我的 Java 应用程序?

c# - 使用 DynamicMethod 编写脚本

Python递归文件夹读取

vba - 删除所有重复行 Excel vba 无法正常工作

java - 将 Excel 数据插入数据库

excel - 在同一语句中使用带有 OR、AND 和通配符的 IF