Office Add-In Menu

  • Thread starter Thread starter Jacques
  • Start date Start date
J

Jacques

Hello,

I am creating a menu for an Office Add-in.
The menu displays OK. But, each time I run
the Office App (Word) it adds another menu
item.

The Word menu bar looks like:
File | Edit | View |.. | My Menu | My Menu | My Menu |..

Do I have to "Find" the menu item first, to see if it
exist, before I create a new menu? If so, how do I
accomplish this?

InitMenuBarItems("&My Menu");

MenuItem1 = CreateButton(
(Office.CommandBarPopup)MenuBarItem,
"Menu Item 1");

private void InitMenuBarItems(string Caption)
{
try
{
MainMenuBar = wordApp.CommandBars["Menu Bar"];

MenuBarItem = MainMenuBar.Controls.Add(

Office.MsoControlType.msoControlPopup, Type.Missing,
Type.Missing, Type.Missing, true);

MenuBarItem.Caption = Caption;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Also, how do I create a separator bar between
menu items?

// I tried this and it displayed a single "-"
on the menu.
MenuItem2 = CreateButton(
(Office.CommandBarPopup)MenuBarItem,
"-");

TIA,
Jacques
 
Jacques,

I would check to see if the item exists for your menu bar already. If
it does, then I would not do anything. Otherwise, add your controls.

If anything, place a unique identifier of some sort in the Tag property
of the controls to identify your menu items which you can compare against
later.

Hope this helps.
 
Hello Nicholas,

Thank you for responding to my posting.
I would check to see if the item exists for your menu
bar already. If it does, then I would not do anything.
Otherwise, add your controls.

I'm certain that's the approach I should take.
How do I check to see if the menu bar already exists?

TIA,
Jacques
 
Back
Top