如何在 vba 中设置选中的属性(格式或控件工具箱)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3025080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:33:04  来源:igfitidea点击:

How to set checked property in vba (format or control toolbox)

excelvbacheckbox

提问by user362729

I'm trying to change the value of my checkbox to true based on a another cell's value

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

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

end if 

How to I change the value property to true for multiple checkbox at the same time

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

For some reason the code that i've tried doesn't do anything at all. P.S. I'm using format checkboxes

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

回答by Dick Kusleika

This will change all Checkboxes

这将更改所有复选框

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

If you need to specify particular checkboxes, then

如果您需要指定特定的复选框,则

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

Checkbox and Checkboxes are hidden properties. You won't get intellisense, but they work.

Checkbox 和 Checkboxes 是隐藏属性。你不会得到智能感知,但它们有效。

回答by rcriii

This works fine for me:

这对我来说很好用:

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

If you are in design mode this will not work.

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

回答by Alexander Suleymanov

This code is true for Office365:

此代码适用于 Office365:

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