PC Review


Reply
Thread Tools Rate Thread

Cannot click twice on custom menu in Excel

 
 
=?Utf-8?B?R2Vycnk=?=
Guest
Posts: n/a
 
      7th Sep 2007
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;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Click Excel custom menu item via MFC automation Bo Zhu Microsoft Excel Programming 0 29th Apr 2010 11:35 AM
Custom right-click menu without changing Excel.App tbd Microsoft Excel Programming 1 12th Oct 2009 02:22 AM
Excel 2007, Custom Right Click Menu Doesn't Work in Table Jeff Microsoft Excel Programming 4 22nd May 2009 04:05 PM
Excel 2007, Custom Right Click Menu Doesn't Work in Table, Help! cpmame Microsoft Excel Programming 3 28th Apr 2009 02:44 AM
Custom Context menu (Right click menu) not working in sheet changeevent. Madiya Microsoft Excel Programming 3 11th Feb 2008 01:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:58 PM.