gpt4 book ai didi

vba - 表单内的自定义 VBA 用户表单热键

转载 作者:行者123 更新时间:2023-12-03 00:29:46 24 4
gpt4 key购买 nike

我希望在不使用加速键的情况下关闭我的用户表单(或其他命令)。

例如,当用户按 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

最佳答案

在Access中可以直接将函数放入控件的事件代码框中,包括多个控件的相同函数。

在 Excel 和 Word 中,我认为执行此操作的唯一方法是使用 WithEvents。这里有几个链接,指向有关该主题的一些信息。如果这还不够,请谷歌“Excel WithEvents”。 (WithEvents 是一个词。)

Chip Pearson's site

Mr.Excel forum

关于vba - 表单内的自定义 VBA 用户表单热键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17128299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com