Cannot click twice on custom menu in Excel

G

Gerry

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.ExcelLocale1033Proxy.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.ActiveMenuBar;
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.Add(
Office.MsoControlType.msoControlButton, missing,
missing, missing, true);
m1.Caption = "&Choice 1...";
m1.Tag = "choice1";
m1.FaceId = 65;
m1.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
choice1_Click);
m2 = (Office.CommandBarButton)cmdBarControl.Controls.Add(
Office.MsoControlType.msoControlButton, missing,
missing, missing, true);
m2.Caption = "&Choice 2...";
m2.Tag = "choice2";
m2.FaceId = 65;
m2.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
choice2_Click);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}

private void choice1_Click(Microsoft.Office.Core.CommandBarButton
Ctrl, ref bool CancelDefault)
{
MessageBox.Show("Choice 1");
CancelDefault = false;
}
private void choice2_Click(Microsoft.Office.Core.CommandBarButton
Ctrl, ref bool CancelDefault)
{
MessageBox.Show("Choice 2");
CancelDefault = false;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top