我试图通过使用VBA代码来自动化一些开发步骤,并希望在VBE窗口处于活动状态时/在顶部时使用快捷键启动这些宏。有没有办法做到这一点? VBE中的“宏”对话框不提供“选项”按钮,该按钮允许在Excel中正确定义快捷键。我还没有找到通过VBE工具栏自定义解决问题的方法。
答案 0 :(得分:0)
F5键是我们运行该快捷方式的快捷键。可以通过将指针悬停在工具栏的“继续”选项上来查看此内容,从而显示对话框。
答案 1 :(得分:0)
您不能在VBE中定义键盘快捷键。
只要您的子例程没有参数:
如果您的子例程需要某些参数(即使它只是可选的),则只有具有直接窗口的方法才有效。但是您可以编写一个简短的包装程序来调用您要调用的子程序。
答案 2 :(得分:0)
感谢您对我的问题的答复。我知道那里提供的选项。似乎在VBE中没有真正的快捷键功能,我最终使用了一个自定义菜单来访问要在VBE会话期间启动的VBA代码。我现在可以通过一个宏(我称DM
= DeveloperMenu的简称)访问所有它们(分布在几个模块上,并部分地带有长的描述,如名称)。我(仍然)需要通过即时窗口来启动。
下面的代码。当然,特定的菜单项是针对我的环境定制的,需要进行调整。
Sub Dm(Optional dummy As Boolean)
Call CreateAndDisplayDevelopmentPopUpMenu
End Sub
Sub CreateAndDisplayDevelopmentPopUpMenu(Optional dummy As Boolean)
Dim menuName As String
menuName = "Development"
'Delete PopUp menu if it exist
On Error Resume Next
Application.CommandBars(menuName).Delete
On Error GoTo 0
'Create the PopUpmenu
Call DevelopmentPopUpMenu(menuName)
'Show the PopUp menu
On Error Resume Next
Application.CommandBars(menuName).ShowPopup
On Error GoTo 0
End Sub
Sub DevelopmentPopUpMenu(menuName As String)
Dim MenuItem As CommandBarPopup
'Add PopUp menu
With Application.CommandBars.Add(name:=menuName, position:=msoBarPopup, _
MenuBar:=False, Temporary:=True)
'First add buttons
With .Controls.Add(type:=msoControlButton)
.caption = "&RebuildDefs"
' .faceId = 71
.OnAction = "'" & ThisWorkbook.name & "'!" & "'RebuildAllDefs ""True""'"
End With
With .Controls.Add(type:=msoControlButton)
.caption = "&ToggleAddIn"
' .faceId = 71
.OnAction = "'" & ThisWorkbook.name & "'!" & "ToggleAddIn"
End With
'Second menues
Set MenuItem = .Controls.Add(type:=msoControlPopup)
With MenuItem
.caption = "&Watch"
With .Controls.Add(type:=msoControlButton)
.caption = "&Start watch"
' .faceId = 71
.OnAction = "'" & ThisWorkbook.name & "'!" & "startWatch"
End With
With .Controls.Add(type:=msoControlButton)
.caption = "&End watch"
' .faceId = 72
.OnAction = "'" & ThisWorkbook.name & "'!" & "DeleteAllwatches"
End With
End With
Set MenuItem = .Controls.Add(type:=msoControlPopup)
With MenuItem
.caption = "&HeartBeat"
With .Controls.Add(type:=msoControlButton)
.caption = "&Start HeartBeat"
' .faceId = 71
.OnAction = "'" & ThisWorkbook.name & "'!" & "heartBeat"
End With
With .Controls.Add(type:=msoControlButton)
.caption = "St&op HeartBeat"
' .faceId = 72
.OnAction = "'" & ThisWorkbook.name & "'!" & "stopHeartBeat"
End With
End With
End With
End Sub