SlowLearner
SlowLearner

Reputation: 3294

Reserved method names in MS Word VBA

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:

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

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

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

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:

Pressing Tab is intercepted by Public Sub NextCell()

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:

Where can I find a comprehensive list of method names for MS-Word that can be used to override default commands?

Upvotes: 3

Views: 104

Answers (1)

SlowLearner
SlowLearner

Reputation: 3294

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

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

snippet from 2.9.75 Fci

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

Some Usage Notes

  • 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

  • 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)

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

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

and

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

Upvotes: 2

Related Questions