使用转义按钮关闭userform [英] Close userform with escape button
问题描述
-
当我按 esc 按钮,然后关闭
Userform1
-
当我在
TextBox1 $ c中输入
打开
应该显示$ c>然后Userform2
。另外在Userform1
中自动清除TextBox1
。
我尝试了以下代码:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms。 returnInteger)
如果textbox1.value =open,那么
userform2.show
textbox1.value =
End If
End Sub
关闭userform1与 Esc
如果您没有对userform进行任何控制,那么只需使用此代码
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
如果KeyAscii = 27然后卸载我
End Sub
如果你说一个TextBox和一个命令按钮,那么使用这个
Private Sub UserForm_Initialize()
CommandButton1.Cancel = True
End Sub
Private Sub TextBox1_KeyPress(ByV al KeyAscii As MSForms.ReturnInteger)
如果KeyAscii = 27然后卸载我
End Sub
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
如果KeyAscii = 27然后卸载我
End Sub
Private Sub CommandButton1_Click()
卸载我
End Sub
如果您有任何其他控件可以关注焦点,那么您将不得不使用该控件的 KeyPress
事件,如当我向textbox1输入open时,我为 TextBox
,然后userform2显示还自动在userform1中清除textbox1。
KeyPress
将只捕获一个键。使用更改
事件来比较文本框中的内容。
Private Sub TextBox1_Change()
如果LCase(TextBox1.Value)=open,然后
TextBox1.Value =
UserForm2.Show
End If
End Sub
I have 2 questions.
When I pressed esc button then close
Userform1
When I input
open
inTextBox1
thenUserform2
should show. Also clearTextBox1
inUserform1
automatically.
I have tried the below code:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If textbox1.value = "open" then
userform2.show
textbox1.value =""
End If
End Sub
Close userform1 with Esc
If you don't have any controls on userform then simply use this code
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 27 Then Unload Me
End Sub
If you have say a TextBox and a Command Button then use this
Private Sub UserForm_Initialize()
CommandButton1.Cancel = True
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 27 Then Unload Me
End Sub
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 27 Then Unload Me
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
If you have any other control that can take focus then you will have to use the KeyPress
event of that control like I did for TextBox
when I input "open" to textbox1 then userform2 showed also clear textbox1 in userform1 automatically.
KeyPress
will capture only one key. Use the Change
event to compare what is there in the textbox.
Private Sub TextBox1_Change()
If LCase(TextBox1.Value) = "open" Then
TextBox1.Value = ""
UserForm2.Show
End If
End Sub
这篇关于使用转义按钮关闭userform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!