![]() |
Cannot click twice on custom menu in Excel
I'm using Visual Studio for office to create an Excel Addin. I've created a
sample menu, with 2 methods. If I select a menu item, it displays my dialog box. After I close it my menu will not display again. It won't drop down when clicked on. Do you know why? (BTW, using C# not VB) If you click choice1 or choice2, then you are done, can't do it twice. Code below: private void ThisAddIn_Startup(object sender, System.EventArgs e) { #region VSTO generated code this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.Ex celLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application); #endregion CheckIfMenuBarExists(); AddMenuBar(); } // Create the menu, if it does not exist. private void AddMenuBar() { try { Office.CommandBarButton menuCommand; Office.CommandBarPopup cmdBarControl = null; Office.CommandBar menubar = (Office.CommandBar)Application.CommandBars.ActiveM enuBar; int controlCount = menubar.Controls.Count; string menuCaption = "&Stockwatch Quotes"; // Add the menu. cmdBarControl = (Office.CommandBarPopup)menubar.Controls.Add( Office.MsoControlType.msoControlPopup, missing, missing, controlCount, true); if (cmdBarControl != null) { cmdBarControl.Caption = menuCaption; Office.CommandBarButton m1, m2; // Add the menu command. m1 = (Office.CommandBarButton)cmdBarControl.Controls.Ad d( Office.MsoControlType.msoControlButton, missing, missing, missing, true); m1.Caption = "&Choice 1..."; m1.Tag = "choice1"; m1.FaceId = 65; m1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler( choice1_Click); m2 = (Office.CommandBarButton)cmdBarControl.Controls.Ad d( Office.MsoControlType.msoControlButton, missing, missing, missing, true); m2.Caption = "&Choice 2..."; m2.Tag = "choice2"; m2.FaceId = 65; m2.Click += new Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler( choice2_Click); } } catch (Exception e) { MessageBox.Show(e.Message); } } private void choice1_Click(Microsoft.Office.Core.CommandBarButt on Ctrl, ref bool CancelDefault) { MessageBox.Show("Choice 1"); CancelDefault = false; } private void choice2_Click(Microsoft.Office.Core.CommandBarButt on Ctrl, ref bool CancelDefault) { MessageBox.Show("Choice 2"); CancelDefault = false; } |
All times are GMT +1. The time now is 05:07 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com