How is the Tool Menu next to the cursor called? Can it be edited?

Solution 1:

There are actually a number of these context menus, the one that appears most often is the Text Context Menu.

These menus can be edited, but not directly through the Word Interface. They can be edited in XML and using vba. Such edits can be saved in either the Normal.dotm template or a global template or another document template (or even in a document).

See Greg Maxey's page on this. Customize the Shortcut Menus Here is the code on that page to add a command to the menu.

Option Explicit
' Greg Maxey
' https://gregmaxey.com/word_tip_pages/customize_shortcut_menu.html
Dim oPopUp As CommandBarPopup
Dim oCtr As CommandBarControl
'
Sub BuildControls()
' Greg Maxey
' https://gregmaxey.com/word_tip_pages/customize_shortcut_menu.html
Dim oBtn As CommandBarButton
  'Make changes to the Add-In template
  CustomizationContext = ThisDocument.AttachedTemplate
  'Prevent double customization
  Set oPopup = CommandBars.FindControl(Tag:="custPopup")
  If Not oPopup Is Nothing Then GoTo Add_Individual
  'Add PopUp menu control to the top of the "Text" short-cut menu
  Set oPopUp = CommandBars("Text").Controls.Add(msoControlPopup, , , 1)
  With oPopUp
   .Caption = "My Very Own Menu"
   .Tag = "custPopup"
   .BeginGroup = True
  End With
  'Add controls to the PopUp menu
  Set oBtn = oPopUp.Controls.Add(msoControlButton)
  With oBtn
    .Caption = "My Number 1 Macro"
    .FaceId = 71
    .Style = msoButtonIconAndCaption
    'Identify the module and procedure to run
    .OnAction = "MySCMacros.RunMyFavMacro"
  End With
  Set oBtn = Nothing
  'Add a Builtin command using ID 1589 (Co&mments)
  Set oBtn = oPopUp.Controls.Add(msoControlButton, 1589)
  Set oBtn = Nothing
  'Add the third button
  Set oBtn = oPopUp.Controls.Add(msoControlButton)
  With oBtn
    .Caption = "AutoText Complete"
    .FaceId = 940
    .Style = msoButtonIconAndCaption
    .OnAction = "MySCMacros.MyInsertAutoText"
  End With
  Set oBtn = Nothing
Add_Individual:
  'Or add individual commands directly to menu
  Set oBtn = CommandBars.FindControl(Tag:="custCmdBtn")
  If Not oBtn Is Nothing Then Exit Sub
  'Add control using built-in ID 758 (Boo&kmarks...)
  Set oBtn = Application.CommandBars("Text").Controls.Add(msoControlButton, 758, , 2)
  oBtn.Tag = "custCmdBtn"
  If MsgBox("This action caused a change to your Add-In template." _
     & vbCr + vbCr & "Recommend you save those changes now.", vbInformation + vbOKCancel, _
     "Save Changes") = vbOK Then
    ThisDocument.Save
  End If
  Set oPopUp = Nothing
  Set oBtn = Nothing
lbl_Exit:
  Exit Sub
End Sub

Those added controls run macros and built-in commands.

Here are the two sample macros.

Sub RunMyFavMacro()
  MsgBox "Hello " & Application.UserName & ", this could be the results of your code."
lbl_Exit:
  Exit Sub
End Sub

Sub MyInsertAutoText()
  On Error GoTo Err_Handler
  'Mimics pressing F3 key to create an autotext/buildingblock
  Application.Run MacroName:="AutoText"
  Exit Sub
Err_Handler:
  Beep
  Application.StatusBar = "The specified text is not a valid AutoText\BuildingBlock name."
End Sub

He goes on to explain the use of the FaceID, Control ID, and custom icons.

Finding out which Context Menu is being displayed

Ron DeBruin at the bottom of his page on Excel Context Menus, provides a link to a little Add-In from Microsoft that adds the name of each context menu at the bottom of the menu. Here are screenshots with the Add-In active.

screenshot of context menu

screenshot of context menu 2

Even though it says it is for Office 2010, it works fine with Office 2019.