Modify Context menus

时光毁灭记忆、已成空白 提交于 2020-01-06 20:29:20

问题


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"

Please Assist Thinus


回答1:


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.

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.

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.

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.



来源:https://stackoverflow.com/questions/36445064/modify-context-menus

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!