禁用 Text_Change 事件 VBA [英] Disable Text_Change event VBA
本文介绍了禁用 Text_Change 事件 VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的
有没有办法禁用 Textbox_change 事件?我试试
Is there a way to disable Textbox_change event?I try
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
推荐答案
我通常定义自己的布尔值,如下所示:
I usually define my own boolean this looks like this:
Public DisableEvents As Boolean
Private Sub SomeObject_Change()
If Not DisableEvents Then
DisableEvents = True
' do_stuff
DisableEvents = False
End If
End Sub
这有效并防止您以其他方式创建的无限循环.
This works and prevent the infinite loop you otherwise create.
这篇关于禁用 Text_Change 事件 VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文