我想让我的用户窗体关闭(或其他命令)而不使用加速键。
例如,当用户按 F4 时,会从 Excel 打开以下表单。我也希望它也用 F4 关闭(卸载我)。
这是我目前正在使用的,尽管它看起来不必要地大:
Private Sub TextBoxA_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxB_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxC_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxD_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxE_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxF_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxG_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxH_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxI_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxJ_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxK_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxM_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxN_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Private Sub TextBoxO_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Sub moveme(keycode As Integer)
If keycode = 115 Then Unload Me
End Sub
我想我正在寻找这样的东西,但我不知道:
loop:
Private Sub TextBox[i]_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
Sub moveme(keycode As Integer)
If keycode = 115 Then Unload Me
End Sub