我正在尝试使用Application.OnKey
方法在Excel 2013中按特定键时执行sub。
我有以下代码
Public Sub Workbook_Open()
Application.OnKey "{r}", "MyEvent"
Application.OnKey "{t}", "MyEvent"
Application.OnKey "{x}", "MyEvent"
Application.OnKey "{z}", "MyEvent"
End Sub
Public Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "{r}"
Application.OnKey "{t}"
Application.OnKey "{x}"
Application.OnKey "{z}"
End Sub
Public Sub MyEvent()
MsgBox "Hello"
End Sub
当我按下键时,子MyEvent
不会执行。如何修改代码才能使其正常工作?
编辑:我希望按键为:r
,t
,x
和z
而不是{{ 1}}。
答案 0 :(得分:0)
这对我有用。将代码添加到模块,保存工作簿,然后重新打开它。
<!-- ========== Form Bean Definitions ================================== -->
<form-beans>
<form-bean name="helloWorldForm" type="com.mkyong.common.form.helloWorldForm"/>
</form-beans>
<!-- ========== Action Mapping Definitions ============================= -->
<action-mappings>
<action name="helloWorldForm" path="/helloWorldForm" type="com.PracticeProgram.common.action.HelloWorldAction" >
<forward name="success" path="/HelloWorld.jsp" />
</action>
</action-mappings>