By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

Office Add-In Menu

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jacques" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
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

Nov 15 '05 #2

P: n/a
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?
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
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.