光标旁边的工具菜单怎么叫?可以编辑吗?

光标旁边的工具菜单怎么叫?可以编辑吗?

MS Word 中光标旁边的工具菜单叫什么?可以编辑吗?

答案1

实际上有很多这样的上下文菜单,最常出现的是文本上下文菜单

这些菜单可以编辑,但不能直接通过 Word 界面编辑。它们可以在 XML 中编辑,也可以使用 vba 编辑。此类编辑可以保存在 Normal.dotm 模板、全局模板或其他文档模板中(甚至可以保存在文档中)。

请参阅 Greg Maxey 的页面。自定义快捷菜单这是该页面上向菜单添加命令的代码。

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

这些添加的控件运行宏和内置命令。

以下是两个示例宏。

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

他继续解释 FaceID、Control ID 和自定义图标的用途。

找出正在显示的上下文菜单

Ron DeBruin 处于他的 Excel 上下文菜单页面,提供了一个 Microsoft 的小插件链接,该插件在菜单底部添加了每个上下文菜单的名称。以下是插件处于活动状态时的屏幕截图。

上下文菜单的屏幕截图

上下文菜单 2 的屏幕截图

尽管它说适用于 Office 2010,但它可以与 Office 2019 配合使用。

相关内容