分配键盘快捷键来运行程序 [英] Assign keyboard shortcut to run procedure

查看:49
本文介绍了分配键盘快捷键来运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 VBA 编辑器中按 F5 时,我总是想运行我的Sub Skynet()"程序.有什么办法可以为这个过程指定一个键盘快捷键.

When I press F5 in the VBA editor I would always like to run my "Sub Skynet()" procedure. Is there any way to assign a keyboard shortcut to this procedure.

推荐答案

为了给表单上的按钮分配一个键盘键,您可以使用此代码,只需将此代码复制到包含该按钮的表单中即可.

For assigning a keyboard key to button on the sheet you can use this code, just copy this code to the sheet which contain the button.

这里Return指定key,get_detail是过程名.

Here Return specifies the key and get_detail is the procedure name.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Application.OnKey "{RETURN}", "get_detail"

End Sub

现在在此工作表中,只要您按 Enter 按钮,就会调用指定的宏.

Now within this sheet whenever you press Enter button the assigned macro will be called.

这篇关于分配键盘快捷键来运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆