Microsoft has awarded Lene Fredborg, DocTools, the Microsoft MVP award for Word each year since 2008. Link to info about the MVP Award at Microsoft.com DocTools - document automation - add-ins, macros and document templates for Microsoft Word (logo) Document Automation
Add-ins & Macros
Document Templates
For Microsoft Word
Document automation, templates, add-ins, macros, for Microsoft Word (graphic)



Bookmark this page | Tip a friend about DocTools


Search thedoctools.com:

Custom Search



Word Tips about...

How to Find Out Which Command Word Executes

You may sometimes need to find the name of the built-in command Microsoft Word executes when you click an icon or select a menu item. For example, you need to know the command name in order to assign a keyboard shortcut to the command. You also need to know the command name if you want a macro to run instead of a built-in command. In order to achieve this, the macro must be named as the command executed by the built-in command. This article explains how to quickly determine the correct command name.

Terms of use

You are welcome to use the macros and Word tips provided on this website. The contents is copyright. You may not reproduce any of contents (with or without modification or credits) elsewhere on the web, or on CD. Please link to the contents on this website instead.

Please note that all free Word tips, macros, add-ins and demos are provided "as is" and without obligation. See also detailed Terms of use.


Example

You want to run your own macro when inserting a comment in order to make all new comments appear with predefined content. You can create a macro with any name and assign the macro to a toolbar (Word 2003 and earlier) or to the Quick Access Toolbar (Word 2007, Word 2010, Word 2013 or Word 2016). But if you want the macro to run automatically instead of the built-in command for inserting a comment, you will need to determine the exact name of the command.

What to do

1. Press Ctrl+Alt+[Plus on the numeric keypad].

The cursor changes into a cloverleaf:

Cloverleaf cursor

2. Click the command you want to find information about (in this example Insert > Comment).

Click on a command with the cloverleaf cursor

Note that you can click until you hit a specific command – the cloverleaf cursor changes to an arrow cursor until positioned over a proper target. If the command is in a menu (or on another tab than the active tab in case of Word 2007, Word 2010, Word 2013 or Word 2016), just make selections until you can click the relevant command.

When you click a command, the Customize Keyboard dialog box opens with the selected command displayed as illustrated below.

Customize Keyboard dialog box

In Word 2007, Word 2010, Word 2013 or Word 2016, you may experience that a target you click does not give any result. I have also seen a message saying "Word encountered a problem" when clicking an item in a list of some kind. However, you should be able to find most command names as explained above.

If you enter the "cloverleaf-mode" by mistake, you can press the Esc key to return to normal mode.

If you know Word 2003 or earlier versions of Word, you may notice that the command names are closely related to the menu structure in those versions of Word. For example, commands found in the Format menu start with "Format" (example: "FormatParagraph" is the name of the command that opens the Paragraph dialog box. The command names are retained in Word 2007 and later versions. If you remember the menu structure you may be able to quess a command name.


IMPORTANT if your version of Word is not in English

The command names you see in the Customize Keyboard dialog box are language-specific. If your Word version is in English, the command names are in English too. If your Word version is in Danish, the command names are in Danish too. When assigning shortcuts, this will not cause problems.

If you are going to use a command name to intercept a built-in command, using the English command name will work even if a user of the macro use another language version of Word. But the opposite is not the case. If you create a macro using a command name in another language than Danish that macro will not run instead of the built-in command on that users computer – Word does not recognize the macro name as the name of a built-in command. This means that you should always use the English command names in macros that are to intercept built-in commands if there is any chance/risk that the macro is going to be used on a computer with another language version of Word than the one you are using.

If you need to find a command name in English and if you know the name in another language, you can, for example, use the Microsoft Language Portal to look up the name in English.


EXAMPLE

The command that is named "FormatParagraph" in English is named "FormaterAfsnit" in Danish.

A macro named "FormatParagraph" will run instead of the built-in command that opens the Paragraph dialog box no matter the language version of Word – English, Danish or another language.

A macro named "FormaterAfsnit" will only run instead of the built-in command that opens the Paragraph dialog box if the Word version is in Danish.

Macro example – intercept a built-in command

If you insert a comment using the built-in command, the result is a comment that shows your user initials (LF in the example below) plus an index number (1 in the example below):

Comment as it appears using the built-in command

If you copy the macro below and insert it in your Normal.dot / Normal.dotm or in a global template, all comments you insert will instead look like this:

Comment as it appears when using the macro

In the illustrations above, formatting marks are visible in order to show exactly what is included in the comment.

The macro

Sub InsertAnnotation()
    With Selection
        'Stop if selection is not in main story
        If Selection.Range.StoryType <> wdMainTextStory Then
            MsgBox "The selection must be in the main story.", _             vbInformation, "Insert Comment"
            Exit Sub
        End If

        'Insert comment
        .Comments.Add Range:=Selection.Range, _
            Text:=vbCr & "Suggestion: " & vbCr & "Ground: "
    End With

End Sub



Top of page

Back to Word Tips ...



Copyright © 2006-2017 Lene Fredborg – DocTools ApS – all rights reserved | Microsoft Word Templates – add-ins – VBA macros | Save time and work more efficiently in Microsoft Word
Privacy policy | Terms of use | Cookies policy | Bookmark this page | Tip a friend | Links | Contact