0

特定のセルのエスケープボタンのOnKeyイベントを定義したい

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

そして、エラーポップアップが表示されました-マクロが使用できないか、無効になっています...
Sub unit()はスタンドアロンプ​​ロシージャとして正常に機能します。

4

1 に答える 1

2

明示的な参照は私のために機能します。Sheet6.unitのようにsheetname.subnameを使用してみてください。

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
于 2012-08-23T10:24:11.333 に答える