A
Armin Zoechel
Hi!
I am very desperate, this problem just drives me crazy!
I built an Excel-Addin in C# 2003 using the MSDN Howto
302901. It works fine the way it is described there. But
when I change the code so that I use a simple menu entry
in Excel's main menu instead of the button, I get the
annoying problem that the code of the menu event click
handler is executed about 40-50 times and then suddenly
stops responding to any clicks! The addin is still loaded
in memory and terminates correctly when I exit Excel,
although.
I am using Windows XP, VS .NET 2003 and Office XP & 2000
(the problem is the same, regardless of the Office
version). Latest service packs.
So what am I doing wrong? I would be most grateful to any
help! Many thanks in advance!
This is the code of the On StartupComplete method. The
rest of the code is exactly the same as in the MSDN
example.
private CommandBarPopup myMenu;
public void OnStartupComplete(ref System.Array custom)
{
CommandBars oCommandBars;
CommandBar oMenuBar;
oCommandBars = (CommandBars)applicationObject.GetType
().InvokeMember("CommandBars", BindingFlags.GetProperty ,
null, applicationObject ,null);
oMenuBar = oCommandBars["Worksheet Menu Bar"];
// In case the button was not deleted, use the existing
one.
try
{
myMenu = (CommandBarPopup)oMenuBar.Controls["My&Menu"];
}
catch(Exception)
{
object oMissing = System.Reflection.Missing.Value ;
myMenu = (CommandBarPopup) oMenuBar.Controls.Add
(MsoControlType.msoControlPopup, oMissing, oMissing,
oMenuBar.Controls.Count, oMissing);
myMenu.Caption = "My&Menu";
CommandBar newMenu = myMenu.CommandBar;
CommandBarButton newMenuItem = (CommandBarButton)
newMenu.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, oMissing);
newMenuItem.Caption = "&Test";
newMenuItem.Tag = "Test Tag";
newMenuItem.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHan
dler(this.MyButton_Click);
}
myMenu.Tag = "My Menu Tag";
System.Windows.Forms.MessageBox.Show("This Addin is
loaded!", "MyCOMAddin");
oMenuBar = null;
oCommandBars = null;
}
I am very desperate, this problem just drives me crazy!
I built an Excel-Addin in C# 2003 using the MSDN Howto
302901. It works fine the way it is described there. But
when I change the code so that I use a simple menu entry
in Excel's main menu instead of the button, I get the
annoying problem that the code of the menu event click
handler is executed about 40-50 times and then suddenly
stops responding to any clicks! The addin is still loaded
in memory and terminates correctly when I exit Excel,
although.
I am using Windows XP, VS .NET 2003 and Office XP & 2000
(the problem is the same, regardless of the Office
version). Latest service packs.
So what am I doing wrong? I would be most grateful to any
help! Many thanks in advance!
This is the code of the On StartupComplete method. The
rest of the code is exactly the same as in the MSDN
example.
private CommandBarPopup myMenu;
public void OnStartupComplete(ref System.Array custom)
{
CommandBars oCommandBars;
CommandBar oMenuBar;
oCommandBars = (CommandBars)applicationObject.GetType
().InvokeMember("CommandBars", BindingFlags.GetProperty ,
null, applicationObject ,null);
oMenuBar = oCommandBars["Worksheet Menu Bar"];
// In case the button was not deleted, use the existing
one.
try
{
myMenu = (CommandBarPopup)oMenuBar.Controls["My&Menu"];
}
catch(Exception)
{
object oMissing = System.Reflection.Missing.Value ;
myMenu = (CommandBarPopup) oMenuBar.Controls.Add
(MsoControlType.msoControlPopup, oMissing, oMissing,
oMenuBar.Controls.Count, oMissing);
myMenu.Caption = "My&Menu";
CommandBar newMenu = myMenu.CommandBar;
CommandBarButton newMenuItem = (CommandBarButton)
newMenu.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, oMissing);
newMenuItem.Caption = "&Test";
newMenuItem.Tag = "Test Tag";
newMenuItem.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHan
dler(this.MyButton_Click);
}
myMenu.Tag = "My Menu Tag";
System.Windows.Forms.MessageBox.Show("This Addin is
loaded!", "MyCOMAddin");
oMenuBar = null;
oCommandBars = null;
}