none
Word 2007 - Customize the shortcut menu RRS feed

  • Question

  • Help!

    The ability to easily customize the shortcut menu in 2007 seems to have overlooked by those upstairs in Microsoft.

    Does anyone know how to program Normal.dotm to enable me to add the command Paste Special to the shortcut menus, in particular those relating to Tables?

    AJPL

     

    Friday, April 23, 2010 9:15 AM

Answers

  • Hello AJPL,

    If I understand you correctly, you are not going to use VSTO technology to achieve this goal. As far as I know, we could create a document-level (Word Document) or an application-level (Word  Add-in) project to add a menu item to context menu. In word 2007, the context menus related to Tables are Whole Table, Tables, Table Cells, Table Headings, Table Lists, Table Pictures, Table Text, and Linked Table. For the names of these context menus, we could refer to the code block in this thread: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/4991cf96-9a95-4931-8bbb-0f954f503a4d.

    To a built-in button to a context menu, I am afraid that it is impossible. However, we could add a menu item (CommandBarButton) to this context menu. Then in the click event handler of this button, use PasteSpecial method of a range or selection [See: PasteSpecial Method]. I have made a slight change with code provided by Scott in the link above. Code like this,

                Office.CommandBars commandbars = Globals.ThisDocument.Application.CommandBars;
                //foreach (Office.CommandBar commandbar in commandbars)
                //{
                //    if (commandbar.Position == Office.MsoBarPosition.msoBarPopup)
                //    {
                //    Debug.Print(commandbar.Name + "; " + commandbar.Id.ToString() + "; " + commandbar.Position.ToString());
                //    foreach (Office.CommandBarControl cbc in commandbar.Controls)
                //        Debug.Print("\t" + cbc.Caption + "--" + cbc.Tag + "--" + cbc.Id.ToString());
                //    }
                //}

                Office.CommandBar ccb = commandbars["Whole Table"] as Office.CommandBar;
                Office.CommandBarButton _wimsBtn;
                object missing = Type.Missing;
                _wimsBtn = (Office.CommandBarButton)ccb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                _wimsBtn.Style = Office.MsoButtonStyle.msoButtonCaption;
                _wimsBtn.Caption = "Test";
                _wimsBtn.Tag = "Test";
                _wimsBtn.Visible = true;
                //_wimsBtn.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(myCommandBarButton_Click);

    However, if you are not using VSTO technology, here is a resource introducing how to customize Word 2007 shortcut menus using VBA: http://www.pcreview.co.uk/forums/thread-3437809.php. This forum is mainly targeted at VSTO technology. You could refer to this forum's PLEASE READ FIRST to know more about this technology.

    If you have any concern for this, please feel free to follow up.

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Bessie Zhao Friday, April 30, 2010 1:44 AM
    Tuesday, April 27, 2010 3:15 AM

All replies

  • Hello AJPL,

    If I understand you correctly, you are not going to use VSTO technology to achieve this goal. As far as I know, we could create a document-level (Word Document) or an application-level (Word  Add-in) project to add a menu item to context menu. In word 2007, the context menus related to Tables are Whole Table, Tables, Table Cells, Table Headings, Table Lists, Table Pictures, Table Text, and Linked Table. For the names of these context menus, we could refer to the code block in this thread: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/4991cf96-9a95-4931-8bbb-0f954f503a4d.

    To a built-in button to a context menu, I am afraid that it is impossible. However, we could add a menu item (CommandBarButton) to this context menu. Then in the click event handler of this button, use PasteSpecial method of a range or selection [See: PasteSpecial Method]. I have made a slight change with code provided by Scott in the link above. Code like this,

                Office.CommandBars commandbars = Globals.ThisDocument.Application.CommandBars;
                //foreach (Office.CommandBar commandbar in commandbars)
                //{
                //    if (commandbar.Position == Office.MsoBarPosition.msoBarPopup)
                //    {
                //    Debug.Print(commandbar.Name + "; " + commandbar.Id.ToString() + "; " + commandbar.Position.ToString());
                //    foreach (Office.CommandBarControl cbc in commandbar.Controls)
                //        Debug.Print("\t" + cbc.Caption + "--" + cbc.Tag + "--" + cbc.Id.ToString());
                //    }
                //}

                Office.CommandBar ccb = commandbars["Whole Table"] as Office.CommandBar;
                Office.CommandBarButton _wimsBtn;
                object missing = Type.Missing;
                _wimsBtn = (Office.CommandBarButton)ccb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                _wimsBtn.Style = Office.MsoButtonStyle.msoButtonCaption;
                _wimsBtn.Caption = "Test";
                _wimsBtn.Tag = "Test";
                _wimsBtn.Visible = true;
                //_wimsBtn.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(myCommandBarButton_Click);

    However, if you are not using VSTO technology, here is a resource introducing how to customize Word 2007 shortcut menus using VBA: http://www.pcreview.co.uk/forums/thread-3437809.php. This forum is mainly targeted at VSTO technology. You could refer to this forum's PLEASE READ FIRST to know more about this technology.

    If you have any concern for this, please feel free to follow up.

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Bessie Zhao Friday, April 30, 2010 1:44 AM
    Tuesday, April 27, 2010 3:15 AM
  • I needed this for a contaxt-menu in excel;

    To get it to work for me in Excel I changed:

    - 'Office' to 'Microsoft.Office.Core'
    - 'Globals.ThisDocument.Application' to 'Globals.ThisAddIn.Application'
    - 'commandbars["Whole Table"]' to 'commandbars["Cell"]'

    and to make it complete; the deligate must look something like:

    private void myCommandBarButton_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool Cancel)
            {
                MessageBox.Show("Test");
            }


    • Edited by XzJ012wQ Tuesday, April 10, 2012 1:30 PM
    Tuesday, April 10, 2012 1:30 PM