Этот код использует TextBox
и CommandButton
на Userform
.
Я только что добавил кнопку, чтобы вы могли переключаться между включен и отключен .
Option Explicit
Private bEnabled As Boolean
Private Sub UserForm_Initialize()
'Starts as FALSE so change to TRUE when form first opens.
bEnabled = True
End Sub
Private Sub TextBox1_Change()
If bEnabled Then
MsgBox "Enabled"
' 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
End If
End Sub
Private Sub CommandButton1_Click()
bEnabled = Not bEnabled
End Sub
Глядя на свой код - вы уверены, что не хотите, чтобы он был в событии AfterUpdate
?