Example #1
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            #region VSTO generated code

            this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application);

            #endregion

            m_DefaultTemplate = Properties.Settings.Default.DefaultTemplate;

            // Register event interest with the Excel Application
            Application.WorkbookBeforeClose += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeCloseEventHandler(Application_WorkbookBeforeClose);
            Application.WorkbookActivate    += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookActivateEventHandler(Application_WorkbookActivate);
            Application.WorkbookDeactivate  += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookDeactivateEventHandler(Application_WorkbookDeactivate);

            // Excel doesn't raise an event when it loses or gains app focus
            m_AppWatcher = new AppWatcher();
            m_AppWatcher.OnWindowHasFocus  += new WindowHasFocus(AppWatcher_OnWindowHasFocus);
            m_AppWatcher.OnWindowLostFocus += new WindowLostFocus(AppWatcher_OnWindowLostFocus);
            m_AppWatcher.Start(Application.Hwnd);

            // Add the button to the Office toolbar
            AddToolbar();
        }
Example #2
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            #region VSTO generated code

             this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application);

             #endregion

             m_DefaultTemplate = Properties.Settings.Default.DefaultTemplate;

             // Register event interest with the Excel Application
             Application.WorkbookBeforeClose += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeCloseEventHandler(Application_WorkbookBeforeClose);
             Application.WorkbookActivate += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookActivateEventHandler(Application_WorkbookActivate);
             Application.WorkbookDeactivate += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookDeactivateEventHandler(Application_WorkbookDeactivate);

             // Excel doesn't raise an event when it loses or gains app focus
             m_AppWatcher = new AppWatcher();
             m_AppWatcher.OnWindowHasFocus += new WindowHasFocus(AppWatcher_OnWindowHasFocus);
             m_AppWatcher.OnWindowLostFocus += new WindowLostFocus(AppWatcher_OnWindowLostFocus);
             m_AppWatcher.Start(Application.Hwnd);

             // Add the button to the Office toolbar
             AddToolbar();
        }