473,657 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

InitMenuBarItem s("&My Menu");

MenuItem1 = CreateButton(
(Office.Command BarPopup)MenuBa rItem,
"Menu Item 1");

private void InitMenuBarItem s(string Caption)
{
try
{
MainMenuBar = wordApp.Command Bars["Menu Bar"];

MenuBarItem = MainMenuBar.Con trols.Add(

Office.MsoContr olType.msoContr olPopup, Type.Missing,
Type.Missing, Type.Missing, true);

MenuBarItem.Cap tion = Caption;
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, ex.Source,
MessageBoxButto ns.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.Command BarPopup)MenuBa rItem,
"-");

TIA,
Jacques
Nov 15 '05 #1
2 3308
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.co m

"Jacques" <an*******@disc ussions.microso ft.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?

InitMenuBarItem s("&My Menu");

MenuItem1 = CreateButton(
(Office.Command BarPopup)MenuBa rItem,
"Menu Item 1");

private void InitMenuBarItem s(string Caption)
{
try
{
MainMenuBar = wordApp.Command Bars["Menu Bar"];

MenuBarItem = MainMenuBar.Con trols.Add(

Office.MsoContr olType.msoContr olPopup, Type.Missing,
Type.Missing, Type.Missing, true);

MenuBarItem.Cap tion = Caption;
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, ex.Source,
MessageBoxButto ns.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.Command BarPopup)MenuBa rItem,
"-");

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.Command BarPopup)MenuBa rItem,
"-");


TIA,
Jacques
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
741
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: "A reference to 'Active DS Type Library' could not be added. The type library wrapper tool 'tlbimp' cannot be found on this system. Please re-install Visual Studio." This occurs regardless of the actual tlb or dll selected and happens on...
1
2812
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
2013
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 out. One I can't even access command bars unless I: namespace Office = Interop::Office; But the the whole IDE crashes when I: Office:: I mean the whole thing goes down after adding the second colon.
0
1080
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 following code that I've found: .... ChartSpace1.Clear() ChartSpace1.Charts.Add()
2
2794
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 Microsoft.Office.Interop.Excel.Workbook xApp.Workbooks.Add() ERROR --> COMException (0x800a03ec): Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk space If I replace it with xWB =...
1
2099
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 assembly for Office web components and what I'm trying to do here is to create a PivotTable object (which is fine) but then I want to add it to a web page (e.g.
1
1710
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 supported? I'm working with .NET 1.1. Thanks.
2
10713
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 following error: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154. When reaching the line: Outlook.Application outlookApp = new...
9
1152
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
1002
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 Offices? Is it possible?
0
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.