http://www.cnblogs.com/sun/archive/2012/03/05/2380542.html
用这种方式多建立几个按钮后,按钮只是响应几次.然后就不响应了.怎么办????

解决方案 »

  1.   

    http://topic.csdn.net/u/20101216/17/385eb771-13a4-47a8-a097-273b6c6acd34.html
    这个兄弟和我的一个样子??有没有高人啊?
      

  2.   

    把创建按钮和事件委托放到OnConnection里试一下
      

  3.   


    //我把创建按钮和事件委托放在
     ThisAddIn_Startup(object sender, System.EventArgs e)
    您说的OnConnection在那儿啊 
      

  4.   

    如果你是用VS里的OFFICE开发插件直接做的话,那很简单啊,不需要代码添加什么按键和委托事件,直接添加一个可视化功能区,就可以像VS里控件拖拽的方式添加控件了,还可以直接在控件下编辑事件,很好用的啊
      

  5.   

    如果你是要开发OFFICE2003以下版本的话,我记得用它VS内置的OFFIE插件,以前没发现你说的这种情况啊,还有就是你可以使用VS里的扩展性栏目下的“外接的共享程序”来开发,它是专门针对OFFCIE进行扩展开发的,有现成的部署向导。
      

  6.   

    我是做的vs2005+word2003做的外接程序,在调试的状态下,建立几个按钮后,按钮只是响应几次.然后就不响应了.怎么办????另外在Application.ActiveDocument为什么取不到打开文档的Word.Document呢?
      

  7.   

     private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
               
                Office.CommandBar commandBar = this.Application.CommandBars.Add("sss", Office.MsoBarPosition.msoBarTop, false, true);
                commandBar.Visible = true;            Office.CommandBarButton btnMark = commandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true) as Office.CommandBarButton;
                btnMark.Caption = "test";
                btnMark.Tag = "test";
                btnMark.Style = Office.MsoButtonStyle.msoButtonCaption;           
                btnMark.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btn_Click);
            }
            void btn_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
            {
                MessageBox.Show("Hello button1");
            }
      

  8.   

    出错
    MessageBox.Show(thisApplication.ActiveDocument.Name);
      

  9.   

    你的按钮不是从工具箱里取的吗,自己创建的?你是用什么模式开发的B/s还是c/s?
      

  10.   


    用VS2005做word外接程序并建立了多个按钮
      

  11.   

     CommandBar toolBar;
                try
                {
                    toolBar = WordApp.CommandBars["XXXX"];
                    _firstInitToolbar = false;
                }
                catch (Exception)
                {
                    //如果不存在,创建工具条
                    toolBar = WordApp.CommandBars.Add("XXXX",MsoBarPosition.msoBarTop, false, true);
                    _firstInitToolbar = true;
                }
                //添加按钮
                try
                {
                    if (!_firstInitToolbar)
                    {
                        SetWordEvent();
                        return;
                    }
                    InitBotton(toolBar);
                    _btnOpen.Click += BtnWordOpenClick;
                    _btnSave.Click += BtnWordSaveClick;
                    toolBar.Visible = true;
                }
                catch (Exception)
                {
                    Utils.ShowWarningMessage(SR.GetString("Connect_AddOutlookToolbar_AddButtonFalure"));
                }private void InitBotton(CommandBar toolBar)
            {
                _btnOpen =
                    (CommandBarButton)
                    toolBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing,
                                         Type.Missing);
                _btnOpen.Style = MsoButtonStyle.msoButtonIconAndCaption;
                _btnOpen.Caption = SR.GetString("Connect_InitBotton_Download");
                _btnOpen.Tag = SR.GetString("Connect_InitBotton_edoc2Download");
                _btnOpen.Picture = ConvertImage.Convert(Resources.unfolder);            _btnSave =
                    (CommandBarButton)
                    toolBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing,
                                         Type.Missing);
                _btnSave.Style = MsoButtonStyle.msoButtonIconAndCaption;
                _btnSave.Caption = SR.GetString("Connect_InitBotton_Upload");
                _btnSave.Tag = SR.GetString("Connect_InitBotton_edoc2Upload");
                _btnSave.Picture = ConvertImage.Convert(Resources.Save);
            }
     private void BtnWordOpenClick(CommandBarButton ctrl, ref bool cancel)
            {
                OpenWord();
            }private void BtnWordSaveClick(CommandBarButton ctrl, ref bool cancel)
            {
                SaveWord();
            }可以解决你的问题
      

  12.   

    看看这种方式
     if (application is OutLookApplication)
                    {
                        _outlookApp = application as OutLookApplication;
                        _inspectors = _outlookApp.Inspectors;
                        _inspectors.NewInspector += InspectorsNewInspector;
                        _selectExplorers = _outlookApp.Explorers;
                        _selectExplorers.NewExplorer += NewExplorerEvent;
                        AddOutlookToolbar(_outlookApp.ActiveExplorer());
                    }
                    else if (application is WordApplication)
                    {
                        WordApp = application as WordApplication;
                        WordApp.DocumentBeforeSave += WordAppDocumentBeforeSave;
                        AddWordToolbar();
                        
                        TaskPane.WApplication = WordApp;
                    }
                    else if (application is ExcelApplication)
                    {
                        _excelApp = application as ExcelApplication;
                        _excelApp.WorkbookBeforeSave += ExcelAppDocumentBeforeSave;
                        AddExcelToolbar();                    TaskPane.EApplication = _excelApp;
                    }
                    else if (application is PowerPointApplication)
                    {
                        _powerPointApp = application as PowerPointApplication;
                        _powerPointApp.PresentationSave += PowerPointAppDocumentBeforeSave;
                        AddPowerPointToolbar();                    TaskPane.PApplication = _powerPointApp;
                    }