473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Office Add-In Menu

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
2 3281
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: jemmaq99 | last post by:
Using Visual Studio .NET 2003 I've tried to add a COM reference to a Windows Form project via the Add Reference dialog (specifically the Active DS Type Library) but always get the error message: ...
1
by: cybertof | last post by:
Hello, Could you please tell me what's wrong with this code (c# office code behind) : protected void ThisWorkbook_Open() { try {
3
by: Mike Duncan | last post by:
Helo All - I am working on a good ol Microsoft Word Control for windows forms. I have the control displayed and it sizes and moves but when I start to try and mess with the command bars It freaks...
0
by: Tom Rahav | last post by:
Dear All! I use Visual Basic .NET 2003 and want to produce graphs by using Office Chart 11.0. I would like to provide this chart with data from an Office Spreadsheet 11.0 and I use the...
2
by: timtai | last post by:
I am trying to create an excel report from my aspx.vb code. I got the following error trying to add a workbook: Dim xApp As New Microsoft.Office.Interop.Excel.Application Dim xWB As...
1
by: John | last post by:
Hi all, I did post this about 10 hours ago thinking I would have received an answer now but it is quite urgent. How do I add a COM object to a web form? I notice there's a primary interop...
1
by: Steve Murphy | last post by:
I have an existing project that will require some MS Office integration. Can I add that to a the existing project, or do I need to add a new MS Office project? Also, is just Word and Excel...
2
by: RodneyAnonymous | last post by:
I've got some code for composing an e-mail from the contents of an RTF box. The first time I execute it, everything works fine. If I close my app and then re-run it, however, I always receive the...
9
by: John | last post by:
Hi Is vs 2008 pro sufficient to write office add-Ins or do I need vsto 2005 SE as well to write office add-Ins? Thanks Regards
0
peochei
by: peochei | last post by:
What is the most appropriate way of creating .NET add-ons and registering them on Office Word? Where can I read about it? How to use an add-on created with Office 2007 installed with older...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.