修改上下文菜单 [英] Modify Context menus

查看:42
本文介绍了修改上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码在 Word 2013 右键菜单上添加菜单项:

I have the following code to add a menu item on the Word 2013 right click menu:

    Sub CreateMenuItem()
        Dim MenuButton As CommandBarButton
        With CommandBars("Text")
            Set MenuButton = .Controls.Add(msoControlButton)
            With MenuButton
                .Caption = ChrW(&H2714) '"Correct"
                .Style = msoButtonCaption
                .OnAction = "InsertMark"
            End With
        End With
    End Sub

问题是当我右键单击文本框或表格时,新菜单项未显示.

The issue is that the new menu item is not displayed when I right click on a Text box or a table.

如何删除我不使用的菜单项,例如翻译"

How do I remove a menu item that is not used by me, for example "Translate"

请帮忙提纳斯

推荐答案

Word 为每个上下文相关菜单提供了一个完全不同的 CommandBar 对象,而不是动态更改单个菜单的内容.这意味着您需要针对您的命令出现的每个上下文进行更改.

Word provides a completely different CommandBar object for each context-sensitive menu, rather than dynamically changing the contents of a single menu. That means you need to make the change for each context in which your command should appear.

您可以通过循环集合并写出各种属性(例如,在新文档中)来生成 CommandBar 列表.然后你必须检查该列表,挑选出可能的候选者,运行你的代码,然后看看你是否猜对了.

You can generate a list of CommandBars by looping the collection and writing the various properties out (for example, in a new document). Then you have to inspect that list, pick out the likely candidates, run your code then see if you guessed correctly.

您要非常小心在 Word 中保存这些更改的位置.如果您没有特别指定,Word 可以将更改保存在一个位置并在另一个位置删除它(假设您撤消"了您的更改).这确实会破坏 Word 配置并使用户非常不满意.所以总是在改变CommandBars的代码开头使用Application.CustomizationContext.CustomizationContext 可以是任何 DocumentTemplate 对象.

You want to be very careful where these changes are SAVED in Word. If you don't specify it specifically, Word could save the change in one place and delete it (assuming you "undo" your changes) in a different one. This can really muck up the Word configuration and make users extremely unhappy. So always use Application.CustomizationContext at the beginning of code that changes the CommandBars. The CustomizationContext can be any Document or Template object.

注意:CommandBars 对象实际上自 Word 2010 起已弃用.从 Word 2013 起,应使用 Ribbon XML 自定义上下文菜单.只是说...在未来的版本中,您的代码可能不再有效.

NOTE: The CommandBars object is actually deprecated as of Word 2010. From Word 2013 onwards the context menus should be customized using Ribbon XML. Just saying... It's possible that in a future version your code will no longer work.

这篇关于修改上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆