gpt4 book ai didi

vba - 如何在VBA中处理复选框值?

转载 作者:行者123 更新时间:2023-12-03 02:33:19 29 4
gpt4 key购买 nike

我有以下示例:

Private Sub setCheck(ByVal val1 As Boolean, ByVal val2 As Boolean, ByVal val3 As Boolean)
With userForm1
.checkboxOne.Value = val1
.checkboxTwo.Value = val2
.checkboxThree.Value = val3
End With
End Sub

Private Sub checkboxOne_Change()
Call setCheck(True, False, False)
End Sub

Private Sub checkboxTwo_Change()
Call setCheck(False, True, False)
End Sub

Private Sub checkboxThree_Change()
Call setCheck(False, False, True)
End Sub

可以仅在一个方向单击支票。这意味着,如果我第一次单击 checkboxOne,我将无法再次检查它。我需要做什么?

最佳答案

您遇到的问题是在初始化复选框的值后,设置其值将导致触发复选框的 ClickChange 事件。这会导致无限循环,从而有效地锁定复选框。

enter image description here

解决这个问题的方法是使用类变量来忽略更新期间对 setCheck 的后续调用。

Private EditMode As Boolean

Private Sub setCheck(ByVal val1 As Boolean, ByVal val2 As Boolean, ByVal val3 As Boolean)
If Not EditMode Then
EditMode = True
With UserForm1
.checkboxone.Value = val1
.checkboxtwo.Value = val2
.checkboxthree.Value = val3
End With
EditMode = False
End If
End Sub

Private Sub checkboxOne_Change()
setCheck True, False, False
End Sub

Private Sub checkboxTwo_Change()
setCheck False, True, False
End Sub

Private Sub checkboxThree_Change()
setCheck False, False, True
End Sub

关于vba - 如何在VBA中处理复选框值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40977967/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com