Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Keybinding Organizer AddIn
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!


The purpose of this Microsoft Word Tips & Microsoft Word Help page is to provide a quick macro solution to create a composite listing of all keybindings and keyboard shortcuts and publish my Keybinding Organizer AddIn.  The composite listing includes all custom keybindings (shortcuts) which you have defined and assigned to execute commands, macros, styles, fonts, building blocks, or common symbols, and the current shortcut combinations defined for Words built-in commands.


Note: Whether a bug or by design, custom keybindings defined using the category wdKeyCategoryMacro will not appear in the All Commands Listing.

A representative list is shown below:

keybinding_009

Background\Discussion

I've been a mouse man for a very long time.  Primarily I use the mouse because, if for no other reason, I can't remember the keyboard shortcuts for all the various Word commands!

I knew that in Word, at least versions 2003 - 2013, I could create a list of current keyboard settings using the Word command "ListCommands" and that I could print (hard copy) a list of custom key assignments.    

This left me with a two separate incomplete lists:

Using the following macro, I can create a composite, complete listing of keyboard shortcuts that I can save as a Word document or print.

VBA Script:
Option Explicit
Sub ListCompositeShortcuts()
Dim oDoc As Word.Document
Dim oDocTemp As Word.Document
Dim oKey As KeyBinding
Dim oTbl_1 As Word.Table, oTbl_2 As Word.Table
Dim oRng As Word.Range
Dim lngIndex As Long
Dim oRow As Word.Row

  'Create a new document for listing composite shortcuts.
  Set oDoc = Documents.Add(, , wdNewBlankDocument)
  Set oRng = oDoc.Range
  System.Cursor = wdCursorWait
  Application.ScreenUpdating = False
  CustomizationContext = NormalTemplate 'or the template\document to evaluate.
  'List and sort custom keybindings.
  For lngIndex = 1 To KeyBindings.Count
    Set oKey = KeyBindings(lngIndex)
    oRng.InsertAfter vbCr & oKey.KeyCategory & vbTab & oKey.Command _
                   & vbTab & oKey.KeyString
    'Update status bar.
    Application.StatusBar = "Processing custom keybinding " & lngIndex & " of " & _
                             KeyBindings.Count & ".  Please wait."
    DoEvents
  Next lngIndex
  'Show progress to user.
  With Application
    .ScreenUpdating = True
    .ScreenRefresh
    .ScreenUpdating = False
  End With
  'Convert text to table or create table. Leave empty paragraph beginning the document.
  oRng.MoveStart wdParagraph, 1
  If Len(oRng.Text) > 2 Then
    Set oTbl_1 = oRng.ConvertToTable
  Else
    Set oTbl_1 = oRng.Tables.Add(oRng, 2, 3)
  End If
  'Format table.
  With oTbl_1
    .Style = "Table Grid"
    .Range.NoProofing = True
    With .Rows
      .Add BeforeRow:=oTbl_1.Rows(1)
      .Add BeforeRow:=oTbl_1.Rows(1)
    End With
    With .Rows(1)
      .HeadingFormat = True
      With .Range
      .Cells.Merge
        With .Cells(1).Range
          .ParagraphFormat.Alignment = wdAlignParagraphCenter
          .Text = "Current Keyboard Settings - Custom Key Bindings"
          .Font.Bold = True
        End With
      End With
    End With
    With .Rows(2)
      .HeadingFormat = True
      .Shading.BackgroundPatternColor = wdColorGray10
      .Cells(1).Range.Text = "Category"
      .Cells(2).Range.Text = "Name/Symbol"
      .Cells(3).Range.Text = "Shortcut Key Combination"
    End With
    For lngIndex = 3 To .Rows.Count
      Select Case Left(.Rows(lngIndex).Cells(1).Range.Text, _
             Len(.Rows(lngIndex).Cells(1).Range.Text) - 2)
        Case "1": .Rows(lngIndex).Cells(1).Range.Text = "Command"
        Case "2": .Rows(lngIndex).Cells(1).Range.Text = "Macro"
        Case "3": .Rows(lngIndex).Cells(1).Range.Text = "Font"
        Case "4": .Rows(lngIndex).Cells(1).Range.Text = "BuildingBlock\AutoText"
        Case "5": .Rows(lngIndex).Cells(1).Range.Text = "Style"
        Case "6": .Rows(lngIndex).Cells(1).Range.Text = "Symbol"
      End Select
    Next lngIndex
    'Sort on category.
    .Sort True, 1
  End With
  'Add and format document title.
  With oDoc.Paragraphs(1).Range
    .InsertBefore "Composite Shortcut List"
    .Style = "Title"
  End With
  'Show progress to user.
  With Application
    .ScreenUpdating = True
    .ScreenRefresh
    .ScreenUpdating = False
  End With
  'Add paragraph separator.
  oRng.InsertAfter vbCr
  oRng.Collapse wdCollapseEnd
  'Create the built-in list using the Word command.
  Application.ListCommands ListAllCommands:=0
  'This creates a new active document.
  Set oDocTemp = ActiveDocument
  'Clean up Word 2003 list.
  With Application
    If CLng(Left(.Version, 2)) < 12 Then
      .ScreenUpdating = True
      .ScreenRefresh
      .ScreenUpdating = False
      .StatusBar = "Processing temporary list.  Please wait"
      With oDocTemp.Tables(1)
        .Columns(4).Delete
        For lngIndex = oDocTemp.Tables(1).Rows.Count To 1 Step -1
          Set oRow = oDocTemp.Tables(1).Rows(lngIndex)
          If Len(oRow.Cells(2).Range) = 2 Then
            oRow.Delete
          End If
          DoEvents
        Next lngIndex
      End With
    End If
  End With
  'Get the list (table) and kill the document.
  oDocTemp.Range.Copy
  oDocTemp.Close wdDoNotSaveChanges
  'Ensure the composite list is the active document.
  oDoc.Activate
  'Paste the copied table into the composite list.
  oRng.Paste
  Set oTbl_2 = oDoc.Tables(2)
  'Format table.
  With oTbl_2
    .Style = "Table Grid"
    With .Range
      .Font.Bold = False
      .NoProofing = True
    End With
    .PreferredWidthType = wdPreferredWidthPercent
    .PreferredWidth = 100
    .Rows.Add BeforeRow:=oTbl_2.Rows(1)
     With .Rows(1)
      .HeadingFormat = True
      With .Range
        .Cells.Merge
        With .Cells(1).Range
          .ParagraphFormat.Alignment = wdAlignParagraphCenter
          .Text = "Current Keyboard Settings - All Commands"
          .Font.Bold = True
        End With
      End With
    End With
    For lngIndex = 2 To .Rows.Count
      Application.StatusBar = "Processing built-in keybinding " & lngIndex - 1 _
                              & " of " & oTbl_2.Rows.Count - 1 & ".  Please wait."
      With .Rows(lngIndex)
        .Cells(2).Merge .Cells(3)
        .Cells(2).Range.Text = Replace(.Cells(2).Range.Text, vbCr, "")
      End With
      DoEvents
    Next lngIndex
    With .Rows(2)
      .HeadingFormat = True
      .Shading.BackgroundPatternColor = wdColorGray10
      .Cells(1).Range.Text = "Command Name"
      .Cells(2).Range.Text = "Shortcut Key Combination"
    End With
    .Range.Cells.DistributeWidth
  End With
  'Prevent (or try to prevent) a blank page at end of document.
  Do While Len(oDoc.Paragraphs.Last.Previous.Range) = 1
   oDoc.Paragraphs.Last.Previous.Range.Delete
  Loop
  Set oRng = oDoc.Paragraphs.Last.Range
  With oRng
   .Paragraphs(1).SpaceBefore = 0
   .Paragraphs(1).SpaceAfter = 0
   .Paragraphs(1).Range.Font.Size = 1
  End With
lbl_Exit:
  System.Cursor = wdCursorNormal
  Beep
  With Application
    .StatusBar = "Finished!!"
    .ScreenUpdating = True
    .ScreenRefresh
  End With
  Exit Sub
End Sub

Site Note IconSee: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.

Due to the large number of built-in Word shortcuts, it may take a while to process and complete the list.  On my system with my shortcuts it takes about 20 seconds.  The actual time will vary depending on your system speed and the number of shortcuts.  Accordingly, so you won't lose hope and think Word has hung up, I've added a process indicator to the status bar.

keybinding_011

Site Note IconNote:  In Word 2003, the built-in list requires additional processing and will take a few seconds longer to complete. 

Keybinding Organizer Add-In

Following participation in a Microsoft Answers discussion on keybindings, I decided to come back to this topic and try to develop a comprehensive Word template AddIn for working with keybindings.  The following discussion addresses that AddIn and provides a download link.

When placed in the Word Startup folder or loaded manually using the Ribbon Developer tab, Template group the AddIn user interface appears on the Ribbon AddIns Tab:

keybinding_001

Site Note Icon Note: On first use and prior to acknowledging the add-in disclaimer, the "Create Shortcut List" control is disabled.

On first use, when the "Keybindings Organizer" is pressed, the add-in displays the user disclaimer.

keybinding_002

After the accepting the disclaimer, the main UI is presented:

keybinding_003
  1. The user interface multipage control. This control allows the user to view the Main interface, Legend or Disclaimer.
  2. The Custom Keybinding Source listbox control. This control lists the Normal template (by default regardless if the Normal template contains defined custom keybindings), any loaded templates containing one or more defined custom keybindings, and an entry "Keybinding Definition Table" (if the active document contains a properly defined Keybinding Definition Table.  Note for this illustration, I have included a demonstration template containing custom keybindings.
  3. The Custom Keybinding Target listbox control. This control provides a list of all loaded templates and an entry "Keybinding Definition Table" (only if the selected source is NOT Keybinding Definition Table).  The selected source is NOT included in the Target list.
  4. With composite list checkbox control. When Keybinding Definition Table is selected as the target, this control is enabled. When checked and executed, a composite keyboard shortcut list is appended to the output document after the Custom Keybinding List.
  5. The Keybinding Definition List listbox control.  This control provides a listing of all custom keybinding properties in the defined source.
  6. Resting Anchor command button control.  This control inks to an opens this webpage.
  7. Donate command button control.  This control is the most useful control. It is used to show your appreciation for the effort required to produce the AddIn.
  8. Select All command button control. This control is used to select all listed custom keybindings.
  9. CLOSE command button control. This control is used to close the AddIn user interface
  10. Unselect All command button control.  This control is used to unselect all listed custom keybindings.
  11. Deleted selected keybindings checkbox control.  When checked and executed, any selected keybindings are deleted from the selected source.
  12. EXECUTE command button. This control is used to execute and complete processing of selected actions. It is disabled until a valid execute action is defined.
  13. Info command button controls. Used throughout the interface, these controls open secondary information userforms providing amplifying information to the user.

In the example below, the user has selected the Keybinding AddIn Demo Template containing custom keybindings. I loaded the template manually using the Ribbon Developer Tab, Templates Group.

keybinding_004
  1. As it is no longer selected as the source, the normal template now appears in the target list.
  2. The selected template contains five custom keybindings. All defined keybindings are selected by default.
  3. A valid execute process is defined (export selected keybindings from the selected source to the selected target).  The EXECUTE command button is enabled.

When EXECUTE is pressed, the user must confirm the EXECUTE command.

keybinding_005

The result of the defined EXECUTE action is a new Word document containing a properly defined Keybinding Definition Table.

keybinding_006

This document can be saved and used later to restore lost or corrupted keybindings or be used to transfer keybindings to another template.  To restore or transfer keybindings the user simply opens the saved file as the active document and then uses the AddIn as shown below:

keybinding_007

A Legend and Help links are provided in the AddIn for users who may be interested in defining shortcuts using a Keybinding Definition Table:

keybindings_008

Here is an example of a Keybinding Definition Table edited to create a keybinding to set the styles as Heading 2 using Alt+Ctrl+H,2:

keybinding_010

Download AddIn: KEYBINDINGS AddIn

Site Note Icon For more on template add-ins and how to load them, see: Organizing Your Macros/Template Add-ins at: Installing Macros

Site Note IconSee: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.

Site Note iconNote: This tips page, illustrations and examples were developed using Word 2019. The AddIn should be compatible with all previous Ribbon versions of Word for PC.

That's it! I hope you have found this tips page useful and informative.

Share

PAYMENTS/DONATIONS

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

Do you want to make a payment for consulting work or donate to help support this site?

PayPal is a safe, easy way to pay online.

Use the appropriate currency "Donate" button to make a payment or donation.


Search my site or the web using Google Search Engine

Google Search Logo