VSTO 为Office已有右键菜单添加自己的菜单项(word,Excel)

原文: VSTO 为Office已有右键菜单添加自己的菜单项(word,Excel)

 

        private void AddRightMenu()
        {
            Microsoft.Office.Core.CommandBar mzBar = appWord.CommandBars["Text"];    //word文档已有的右键菜单Text

            Microsoft.Office.Core.CommandBar mzBar = appExcel.CommandBars["cell"];    //excel文档已有的右键菜单cell                

            Microsoft.Office.Core.CommandBarControls bars = mzBar.Controls;
            foreach (Microsoft.Office.Core.CommandBarControl temp_contrl in bars)
            {
                string t = temp_contrl.Tag;
                //如果已经存在就删除

                if (t == "Test") {
                    temp_contrl.Delete();
                }
            }
            Microsoft.Office.Core.CommandBarControl comControl = bars.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, missing, missing, missing, true);   //添加自己的菜单项
            Microsoft.Office.Core.CommandBarButton comButton = comControl as Microsoft.Office.Core.CommandBarButton; 
            if (comControl != null)
            {
                comButton.Tag = "Test";
                comButton.Caption = "测试";
                comButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;
                comButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(menuCommand_Click); 
            }
        }

       对于Outlook和PPT具体还不清楚,正在查证中。。。

 

上一篇:java方法 调用 问题


下一篇:Java 读入一个整数,如果是1~5之间,则分别输出5个福娃的名字,否则输出“北京欢迎你”。