Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I want to create an addin that loads automatically in Excel if Excel starts up.

 

First this addin should make a menu, this menu has three modes: local, client and server. The menu has local mode as default.

 

private enum eMenuModus {LokalModus, ClientModus, ServerModus};

public void OnStartupComplete(ref System.Array custom)
{
createmenu(eMenuModus.LokalModus);
}

 

part of sub createmenu :

//....

if(oMenuModus == eMenuModus.LokalModus)
{
MyButton = (ofcore.CommandBarButton) commandBarPopup.Controls.Add(1, omissing , omissing , omissing , omissing);
MyButton.Caption = "&Globale Aktualisierung";
MyButton.Tag = MyButton.Caption;
MyButton.Style = ofcore.MsoButtonStyle.msoButtonIconAndCaption;
MyButton.FaceId = 349;
MyButton.BeginGroup = true;
MyButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.MyButton_Click);
}

//....

ofcore.CommandBarPopup commandBarPopup1 = (ofcore.CommandBarPopup) commandBarPopup.Controls.Add(
ofcore.MsoControlType.msoControlPopup, 1, "", omissing, true);
commandBarPopup1.Caption = "&Modus";
commandBarPopup1.BeginGroup = true;

MyButton = (ofcore.CommandBarButton) commandBarPopup1.Controls.Add(1, omissing , omissing , omissing , omissing);
MyButton.Caption = "&Lokal";
MyButton.Tag = MyButton.Caption;
MyButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.ButtonChangeModus_Click);

MyButton = (ofcore.CommandBarButton) commandBarPopup1.Controls.Add(1, omissing , omissing , omissing , omissing);
MyButton.Caption = "&Client";
MyButton.Tag = MyButton.Caption;
MyButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.ButtonChangeModus_Click);

//...

 

for test i signed the sub ButtonChangeModus_Click for change mode buttons and MyButton_Click for every other button that is clicked

 

ButtonChangeModus_Click and MyButton_Click look like this :

private void MyButton_Click(ofcore.CommandBarButton cmdBarbutton,ref bool cancel) 
{
MessageBox.Show(cmdBarbutton.Caption + " was Clicked","MyCOMAddin");
}

private void ButtonChangeModus_Click(ofcore.CommandBarButton cmdBarbutton,ref bool cancel) 
{
switch(cmdBarbutton.Caption.Replace("&","")) 
{
	case "Lokal":
		createmenu(eMenuModus.LokalModus);
		break;
	case "Client":
		createmenu(eMenuModus.ClientModus);
		break;
	case "Server":
		createmenu(eMenuModus.ServerModus);
		break;
	default:
		break;
}
}

 

The problem is :

- if after excel loads I click on a random button (except change mode buttons), the messagebox comes out. But after that nothing happen if i click on any button (incl. the change mode buttons)

- if i click on the change mode buttons after excel loads, the menu would change into what it suppose to be. But if i change the mode 5 times, and if i click on a button that is on the three modes, then the messagebox appears 5 times too...

 

Can someone please help me how to create the menu in the right way?

 

Thx :)

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...