首页 > 其他 > 详细

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

时间:2015-06-16 12:36:14      阅读:930      评论:0      收藏:0      [点我收藏+]
原文: 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具体还不清楚,正在查证中。。。

 

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

原文:http://www.cnblogs.com/lonelyxmas/p/4580129.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!