【发布时间】:2020-04-09 09:44:57
【问题描述】:
亲爱的,
有没有办法禁用 Textbox_change 事件?我试试
Application.EnableEvents = False
但它不起作用。
If .txtHomeNumber.Value <> "" Then
If IsNumeric(txtHomeNumber.Value) Then
.txtHomeNumber.BackColor = RGB(255, 255, 255)
.txtMobileNumber.BackColor = RGB(255, 255, 255)
.txtParentsNumber.BackColor = RGB(255, 255, 255)
Else: MsgBox "Please enter a valid Home Number in Contact Details section.", vbExclamation, "Contact Details"
Application.EnableEvents = False
.txtHomeNumber.Value = Left(.txtHomeNumber.Value, Len(.txtHomeNumber.Value) - 1)
Application.EnableEvents = True
Exit Sub
End If
End If
【问题讨论】:
-
添加一个模块级布尔变量并将其作为事件的第一行进行检查 -
If bEnabled Then.... <do stuff> Else <don't do stuff> End If。 -
或者不要使用更改事件,因为每次更改都会触发它,使用更新后或退出事件
-
@Darren Bartrup-Cook 我是用户表单使用的新手。您能举个例子吗?非常感谢您的快速回复。
-
什么情况下您不希望触发事件 - 我认为您希望有时触发事件?