Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How do I Remove Menu Items created by Outlook Add-In?

Avatar of esps
esps asked on
Outlook.NET ProgrammingC#
2 Comments1 Solution947 ViewsLast Modified:
Hi Experts

I have a problem with a Visual Studio 2008 Outlook Add-In that creates a main menu item on the Outlook Menu with 2 submenus. For some reason it only removes the submenus and not the Main menu item.

What happens in turn is that the main menu remains and it recreates the main menu with the 2 submenus. The old main menu is there but does not serve any purpose and makes Outlook look very funny especially after there is about 5 of the same main menu items but only one works.

Please see my code for creating and removing the menu. Is there something missing?

Thanks in advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;        
        private Office.CommandBar menuBar;
        private Office.CommandBarPopup newMenuBar;
        private Office.CommandBarButton btnRecording;
        private Office.CommandBarButton btnRegistration;
        private string menuTag = "Main Menu";
        private string recmenuTag = "Menu Item 1";
        private string regmenuTag = "Menu Item 2";
        private void AddMenuBar()
                menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
                    Office.MsoControlType.msoControlPopup, missing,
                    missing, missing, false);
                if (newMenuBar != null)
                    newMenuBar.Caption = "Main Menu Bar Item";
                    newMenuBar.Tag = menuTag;
                    btnRecording = (Office.CommandBarButton)newMenuBar.Controls.
                    Add(Office.MsoControlType.msoControlButton, missing,
                        missing, 1, true);
                    btnRecording.Style = Office.MsoButtonStyle.
                    btnRecording.Caption = "Menu 1";
                    btnRecording.FaceId = 2986;
                    btnRecording.Tag = recmenuTag;
                    btnRecording.Click += new
                    btnRegistration = (Office.CommandBarButton)newMenuBar.Controls.
                    Add(Office.MsoControlType.msoControlButton, missing,
                    missing, 1, true);
                    btnRegistration.Style = Office.MsoButtonStyle.
                    btnRegistration.Caption = "Menu 2";
                    btnRegistration.FaceId = 2936;
                    btnRegistration.Tag = regmenuTag;
                    btnRegistration.Click += new
                    newMenuBar.Visible = true;
            catch (Exception ex)
        private void RemoveMenubar() 
        {    // If the menu already exists, remove it.    
            try {        
                Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)            
                    missing, menuTag, true, true);        
                    if (foundMenu != null) 
            catch (Exception ex) {        
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
Avatar of esps

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers