我试图在代码中添加一行,例如在按下 ESC 键时,该行将结束。
我设法让其他人工作,那里的一些网站说下面的/类似的方法可以工作,尽管我发现相反的情况是正确的。
Sub CellMover()
Application.OnKey "{ESC}", End
Application.OnKey "{UP}", "MoveUp"
Application.OnKey "{DOWN}", "MoveDown"
Application.OnKey "{LEFT}", "MoveLeft"
Application.OnKey "{RIGHT}", "MoveRight"
End Sub
我的希望是,当我下次按下 ESC 时,再次按下任意箭头键,它将不再运行相关的宏。
答案 0 :(得分:-1)
使用Stop
语句确实可以解决问题(实际上是创建一个断点)
Public Sub halt()
Stop 'prevents all further execution
End Sub
因此您的代码应如下所示:
Sub CellMover()
Application.OnKey "{ESC}", "halt"
Application.OnKey "{UP}", "MoveUp"
Application.OnKey "{DOWN}", "MoveDown"
Application.OnKey "{LEFT}", "MoveLeft"
Application.OnKey "{RIGHT}", "MoveRight"
End Sub