如何定义一个范围的OnKey事件?

我想定义特定单元格上的退出button的OnKey事件

Private Sub Worksheet_SelectionChange(ByVal Target As Range) If ActiveCell.Value = "a" Or ActiveCell.Value = "b" Then Application.OnKey "{ESC}", "unit" 

并得到错误popup – macros不可用或被禁用…
子单元()作为一个独立的程序正常工作。

显式引用适用于我,尝试使用sheetname.subname,如Sheet6.unit:

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) Debug.Print ActiveCell.Value If ActiveCell.Value = "d" Or ActiveCell.Value = "e" Then Application.OnKey "{ESC}", "Sheet6.unit" Else Application.OnKey "{ESC}", "" End If End Sub Public Sub unit() Debug.Print "Unit!" End Sub