我在Office Excel 2013中遇到Excel VBA用户窗体事件的问题,如下所示
我已阅读并理解http://www.cpearson.com/excel/SuppressChangeInForms.htm关于抑制UserForm事件并将其分开工作......
在上面的列表2.和3.上面的代码中正常工作(如下所示),并且为CB3触发了无事件。但是,当我这样做时4.检查CB3 - 它会触发CB1和CB2的事件,即使我已将其设置为不触发事件。
感激地收到任何帮助,
祝你好运
肖恩
代码:
Public EnableEvents As Boolean
Private Sub UserForm_Initialize()
Me.EnableEvents = True
End Sub
Private Sub vboInputsSelected_Click()
Me.EnableEvents = False
vboPracticesSelected.value = False 'this line does NOT fire an event
Me.EnableEvents = True
End Sub
Private Sub vboOutputsSelected_Click()
Me.EnableEvents = False
vboPracticesSelected.value = False 'this line does NOT fire an event
Me.EnableEvents = True
End Sub
Private Sub vboPracticesSelected_Click()
Me.EnableEvents = False
vboInputsSelected.value = False 'this line DOES fire an event
vboOutputsSelected.value = False 'this line DOES fire an event
Me.EnableEvents = True
End Sub
答案 0 :(得分:2)
这适合我。当事件进行时,If
会失效。意识到EnableEvents
变量本身没有任何作用来阻止事件。它只是您创建的布尔值。在允许事件发生之前,您需要检查它,以便它做任何事情。
Public EnableEvents As Boolean
Private Sub vboInputsSelected_Click()
If Not EnableEvents Then Exit Sub
Me.EnableEvents = False
vboPracticesSelected.Value = False
Me.EnableEvents = True
End Sub
Private Sub vboOutputsSelected_Click()
If Not EnableEvents Then Exit Sub
Me.EnableEvents = False
vboPracticesSelected.Value = False
Me.EnableEvents = True
End Sub
Private Sub vboPracticesSelected_Click()
If Not EnableEvents Then Exit Sub
Me.EnableEvents = False
vboInputsSelected.Value = False
vboOutputsSelected.Value = False
Me.EnableEvents = True
End Sub