Application.OnKey无法正确重置 [英] Application.OnKey Fails to Reset Properly

查看:168
本文介绍了Application.OnKey无法正确重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试帮助该论坛中的其他用户(

I am trying to help another user in this forum (reference). The goal is to use the Enter key on the numeric keypad to trigger a macro rather than use the Worksheet_Change event macro for the same purpose.

Before anything is run, both Enter keys work identically. You type stuff in, touch either key, the material gets placed in the cell and Selection moves downward. If you just pump either key, Selection just moves downward.

在标准模块中,我放入:

In a standard module I put:

Sub NumericEnter()
    Application.OnKey "{ENTER}", "InsertIntoTables"
End Sub

Sub InsertIntoTables()
    MsgBox "Inserting"
End Sub

运行NumericEnter()后,每次触摸数字键盘上的 Enter 键都会调用相应的宏.普通的 Enter 键不受影响.

After I run NumericEnter(), the Enter key on the numeric keypad calls the proper macro each time it is touched. The normal Enter key is not affected.

然后我尝试通过运行以下命令恢复数字 Enter 键:

I then tried to restore the numeric Enter key by running:

Sub ClearEnter()
    Application.OnKey "{ENTER}", ""
End Sub

数字 Enter 键部分恢复其原始行为.它不再调用宏.它允许将数据输入到单元格中,但完全不移动Selection (常规回车键仍然正常运行)

The numeric Enter key partially reverts to its original behavior. It no longer calls the macro; it allows data entry into cell, but it does not move Selection at all! (the regular enter key still behaves normally)

我不知道自己错过了什么.

I have no idea of what I have missed.

我所看的内容:

  • 普通的回车键,箭头键和TAB键在更改Selection时可以正常工作
  • 单击鼠标可以很好地更改Selection
  • Application.MoveAfterReturnApplication.MoveAfterReturnDirection的值也很好.
  • The normal enter key, the ARROW keys, and the TAB key work just fine at changing Selection
  • Mouse clicking works fine at changing Selection
  • the values of Application.MoveAfterReturn and Application.MoveAfterReturnDirection look fine as well.

推荐答案

仅使用

Application.OnKey "{ENTER}" 

没有第二个参数似乎可以清除宏映射并返回默认的键操作(Excel 2013)

with no second argument seems to clear the macro mapping and return the default key action (Excel 2013)

https://msdn .microsoft.com/en-us/vba/excel-vba/articles/application-onkey-method-excel

expression.OnKey( Key , Procedure )

Procedure参数的说明具有以下内容:

The description for the Procedure parameter has this:

一个字符串,指示要运行的过程的名称. 如果程序 为"(空文本),则按键"时不会发生任何反应. OnKey更改Microsoft Excel中击键的正常结果. 如果 省略了过程,密钥恢复为Microsoft的正常结果 Excel ,以及使用以前的OnKey进行的任何特殊键分配 方法已清除.

A string indicating the name of the procedure to be run. If Procedure is "" (empty text), nothing happens when Key is pressed. This form of OnKey changes the normal result of keystrokes in Microsoft Excel. If Procedure is omitted, Key reverts to its normal result in Microsoft Excel, and any special key assignments made with previous OnKey methods are cleared.

这篇关于Application.OnKey无法正确重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆