我想在Userform上的TextBox中选择/突出显示所有文本。我已经使用.SelStart和.SelLength解决方案找到了> 20个论坛,但它对我不起作用...
我是否需要更改设置或属性才能使用此功能?
这是我的代码:
Private Sub MaterialDescriptionTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(MaterialDescriptionTextBox.Value) > 40 Then
MsgBox "The material description can not exceed 40 characters", vbInformation, "Too many characters"
With Me.MaterialDescriptionTextBox
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
可悲的是,它显示MsgBox没有任何帮助。
由于
答案 0 :(得分:2)
您错过了Cancel = True
。取消取消Exit
事件本身,但之后的任何其他代码仍会运行。
Private Sub MaterialDescriptionTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(MaterialDescriptionTextBox.Value) > 40 Then
MsgBox "The material description can not exceed 40 characters", vbInformation, "Too many characters"
Cancel = True
With MaterialDescriptionTextBox
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
答案 1 :(得分:0)
form userform 属性使 show modal = false