MS Word 2013 导航窗格上下文菜单

问题描述 投票:0回答:2

使用 MS Office 2013:

有谁知道如何获取右键单击导航窗格上的项目时出现的上下文菜单的 CommandBar 项目?

我想添加一些额外的选项来执行“选择标题和内容”按钮返回的范围。

我可以使用 Application.CommandBars("Navigation") 获取导航窗格,但我似乎无法找到与此窗格关联的上下文菜单。我什至迭代了所有命令栏及其控件来查看标题,但我什至找不到带有标题 SubHeading 的控件的命令栏。

欢迎任何想法,我不介意沿着 CustomXml 路线走下去,因为我正在构建 VSTO 插件,我只是希望能够向上下文菜单添加按钮并获取所选标题和内容的范围。

更新 1:添加相关上下文菜单的屏幕截图: enter image description here

更新2: 按照 Eugene 建议的 CustomXml 路线,当我尝试自定义菜单时,我仍然遇到困难:

使用来自 http://www.microsoft.com/en-us/download/details.aspx?id=727 的最新 CustomUI 文档,表明导航窗格的上下文菜单的 idMso 是 ContextMenuNavigationPane,但是以下 xml 不会产生任何结果(添加到 ContextMenuText 时确实有效)。

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <contextMenus>
    <contextMenu idMso="ContextMenuNavigationPane">
      <button id="SomeNavButtonIAdded" label="Some Button i added" />
    </contextMenu>
  </contextMenus>
</customUI>
ms-word vsto word-2013
2个回答
0
投票

您到底想要自定义什么上下文菜单?可以截图吗?

事实是命令栏不再使用(已弃用)。在 Office 2013 中自定义上下文菜单的唯一可能方法是使用 Fluent UI(又名 Ribbon UI)。您可以在 MSDN 中的以下文章中阅读更多相关信息:


0
投票

尝试以下方法用名称标记所有命令栏(也包括上下文菜单)。当我定制它们时,我发现它很有帮助。但是,我认为这些名称并不总是您需要的功能区 xml 名称。

有一件事,原始帖子所指的导航窗格上下文菜单没有被标记。这不是命令栏吗?

Sub LabelAllCommandBars()
    'Use this to label the command bars to see what their names are for use in the
    'customizations of commandbars.
    
    Dim myLabelCtrl As CommandBarButton
    Dim myLabelName As String
    Dim cb As CommandBar
    
    For Each cb In Application.CommandBars
        With cb
            myLabelName = cb.Name
            On Error Resume Next
             'Don't use the Before:= parm, some Controls/menus will raise a "Subscript
             'out-of-range" error. Just let it add it to the end/bottom.
            Set myLabelCtrl = cb.Controls.Add(Type:=msoControlButton, Temporary:=True)
            On Error GoTo 0
            If Not myLabelCtrl Is Nothing Then
                myLabelCtrl.Caption = "Menu Name = " & myLabelName
                myLabelCtrl.Style = msoButtonCaption
            End If
        End With
    Next
End Sub

Sub ResetAllCommandbars()
    Dim cb As CommandBar
    Dim strName As String
    
    On Error GoTo cbError
    'There are a few, "Resume Reading" and "Ribbon" that raise error when attempt to Reset
    For Each cb In Application.CommandBars
        strName = cb.Name
        cb.Reset
    Next
cbError:
    Resume Next
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.