【问题标题】:How to set checked property in vba (format or control toolbox)如何在 vba 中设置选中的属性(格式或控制工具箱)
【发布时间】:2011-03-02 18:58:36
【问题描述】:

我正在尝试根据另一个单元格的值将复选框的值更改为 true

if range("A1").value = "green" then
Checkbox1.value= true

end if 

如何同时将多个复选框的 value 属性更改为 true

由于某种原因,我尝试过的代码根本没有做任何事情。 附:我正在使用格式复选框

【问题讨论】:

    标签: excel vba checkbox


    【解决方案1】:

    这对我来说很好用:

    If range("O26").Value = "green" Then
        CheckBox1.Value = True
        CheckBox2.Value = True
    End If
    

    如果您处于设计模式,这将不起作用。

    【讨论】:

    • 代码给了我一个需要对象的错误(424)我也尝试在我的第一个 Checkbox.value = true 语句之后放置一个 And,但它不起作用。
    【解决方案2】:

    这将更改所有复选框

    Sub Changeboxes()
    
        Dim cb As CheckBox
    
        If Sheet1.Range("a1").Value = "green" Then
            For Each cb In Sheet1.CheckBoxes
                cb.Value = True
            Next cb
        End If
    
    End Sub
    

    如果你需要指定特定的复选框,那么

    Sub ChangeSomeCbs()
    
        If Sheet1.Range("a1").Value = "green" Then
            Sheet1.CheckBoxes("Check Box 1").Value = True
            Sheet1.CheckBoxes("Check Box 2").Value = False
            Sheet1.CheckBoxes("Check Box 3").Value = True
        End If
    
    End Sub
    

    复选框和复选框是隐藏属性。你不会得到智能感知,但它们可以工作。

    【讨论】:

    • 我正在尝试在我的表单上指定我想要打勾的复选框。例如对于 checkbox1 ,我希望用户看到它被勾选了。
    【解决方案3】:

    此代码适用于 Office365:

    If range("O26").Value = "green" Then
        CheckBox1 = True
        CheckBox2 = True
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      • 2017-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      相关资源
      最近更新 更多