none
How to disable menu items in Word 2007/2010? RRS feed

  • Question

  • Why the following code is not working?

    string s=Application.CommandBars[1].Controls[2].Caption;                       
    MessageBox.Show(s.ToString());          
    Application.CommandBars[1].Controls[2].Enabled = false;

    I want to disable the "Open" . How to achieve it?

    Tuesday, May 17, 2011 6:51 AM

Answers

  • Word 2007 and 2010 no longer use the CommandBars object model to control the UI. The Ribbon is the UI in those versions. In order to disable commands in the Ribbon UI you need to include a Ribbon XML in your VSTO add-in or document solution. Then you need to insert a <commands> section with a <command> element for each built-in command you want to re-purpose. For the Open command that element would be:

    <command idMso="FileOpen" enabled="false" />


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Tuesday, May 24, 2011 8:29 AM
    • Marked as answer by Bruce Song Tuesday, May 31, 2011 10:11 AM
    Wednesday, May 18, 2011 6:59 AM
    Moderator

All replies

  • Word 2007 and 2010 no longer use the CommandBars object model to control the UI. The Ribbon is the UI in those versions. In order to disable commands in the Ribbon UI you need to include a Ribbon XML in your VSTO add-in or document solution. Then you need to insert a <commands> section with a <command> element for each built-in command you want to re-purpose. For the Open command that element would be:

    <command idMso="FileOpen" enabled="false" />


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Tuesday, May 24, 2011 8:29 AM
    • Marked as answer by Bruce Song Tuesday, May 31, 2011 10:11 AM
    Wednesday, May 18, 2011 6:59 AM
    Moderator
  • Hi Siva,

    Have you resolved your problem yet, and do the suggestion help you? If you still have any concern on the thread, feel free to follow up.

    Best Regards,




    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 24, 2011 8:30 AM
  • As a follow up to Cindy's post. You can get a list of command ID's (called control ID's) by using the following links:

    For a list of Office 2010 control IDs, see Office 2010 Help Files: Office Fluent User Interface Control Identifiers.

    For a list of Office 2007 control IDs, see 2007 Office System Document: Lists of Control IDs.


    Norm Estabrook
    Tuesday, May 24, 2011 7:26 PM
    Answerer