MS Word VBA中的保留方法名称 [英] Reserved method names in MS Word VBA

查看:90
本文介绍了MS Word VBA中的保留方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MS-Word的VBA中,毫无疑问,在Office的其余部分中,有一些特殊"方法(宏)名称会拦截某些击键/UI命令.例如:

In VBA for MS-Word, and undoubtedly the rest of Office, there are some 'special' method (macro) names that intercept certain keystrokes / UI commands; for example:

按下 Ctrl + z (或QAT上的撤消图标)被Public Sub EditUndo()

Pressing Ctrl + z (or the undo icon on the QAT) is intercepted by Public Sub EditUndo()

按下 Ctrlk + y (或QAT上的重做图标)会被Public Sub EditRedo()

Pressing Ctrlk + y (or the redo icon on the QAT) is intercepted by Public Sub EditRedo()

MS API文档涵盖了 EditUndo EditRedo ,并有助于查找一些内容其他可以覆盖的方法.

The MS API documentation covers EditUndo and EditRedo, and helps find some other methods that can be overridden.

但是NextCellPrevCell似乎都未包含在VBA API文档中.例如,只要在文档表中进行选择,就会更改 Tab 行为:

But neither NextCell nor PrevCell seem to be included in the VBA API documentation. For example Tab behavior is altered whenever the selection is in a document table:

Tab 会被Public Sub NextCell()

按下 Shift + Tab Public Sub PrevCell()

Pressing Shift + Tab is intercepted by Public Sub PrevCell()

这让我想知道是否还有其他特殊方法名称...以及如何找到它们.

This left me wondering if there are any other special method names... and how to find them.

所以,我的问题(在询问过程中找到答案)是:

So, my question (answer found during the asking) is:

推荐答案

The open specification 2.9.75 Fci provides a long list of method names some of which can over-ride commands.

Fci枚举提供了一个13位无符号整数,该整数指定 内置命令.

The Fci enumeration provides a 13-bit unsigned integer that specifies a built-in command.

例如,您可能想包含类似的方法:

For example, you might like to include a method like:

Sub UnlinkFields()
    ' Intercepts Ctrl+Shift+F9 to prevent user from 
    ' unlinking fields and breaking your document
End Sub


一些使用说明

  • 如果将这些方法放在Normal.dotm模板中,它们应该具有 全球范围,并适用于所有打开的文档.

  • If you put these methods in the Normal.dotm template they should have global scope and apply to all open documents.

将方法放入特定的文档模板意味着它将 仅适用于基于该模板的文档

Putting the method into a specific document template means it will only apply to documents based on that template

该模块可以是Public或Private,即如果您使用 Option Private Module.

The module can be Public or Private, i.e. they still work if you use Option Private Module.

该方法可以是公开"或私有"(至少就我的测试而言) 去)

The method can be Public or Private (at least as far as my testing goes)

该方法可以是Sub或Function,例如,这两种方法都可以:

The method can be a Sub or Function, for example both of these work:

Private Function DoubleUnderline()
    ' Ctrl + Shift + D
    Stop
End Function

Public Sub DoubleUnderline()
    ' Ctrl + Shift + D
    Stop
End Function

这篇关于MS Word VBA中的保留方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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