Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > How to remove custom menu after uninstalling add-in
 

How to remove custom menu after uninstalling add-in

Hi,

After uninstalling outlook 2007 add-in using Add or Remove Programs from control panel, my customtop levelmenu item is still there.
Custom menu was added following instructions on link: http://msdn.microsoft.com/en-us/library/0batekf4(VS.80).aspx.
After uninstalling add-in, all submenus dissapears, but top level menu item is still there and I dont know how to remove it!

Is it possible to remove menu item programmatically, since it was added programmatically, and how to do that?

BR

matixsc  Thursday, June 04, 2009 11:59 AM
Hi

In outlook 2007 the latest SP has some new code to improve the Shutdown speed and as such your code may not always be firing as the Outlook Object Model no longer cares for the 3rd Party Addins as much as a lot were holding outlook to keep open and not shutdown properly.

This article explains http://msdn.microsoft.com/en-us/library/dd239276.aspx


Regards

Mike
Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
Mike Walker  Friday, June 19, 2009 8:48 AM
Hello,
Try calling the Reset method of the appropriate commandbars collection. There is blog post about how to do this to clear menu items in a Word add-in here - http://blogs.msdn.com/vsto/archive/2009/04/14/clearing-off-custom-menu-items-in-word-norm-estabrook.aspx. You do not have to set the customization context in Outlook, but you should be able to use the Reset method of the command bars collection as shown in the blog post.
Norm E.
Norm Estabrook
Norm Estabrook - MSFT  Thursday, June 04, 2009 8:23 PM
Thank you for your post Norm, but I think it's not right solution for my problem.
After uninstalling add-in, all custom menus and toolbars from my add-in must be removed and this action must not have any impact to other customizations.

I'm just wondering is it possible that setup on uninstall performs clean up? Uninstall custom action will call dll or exe file which will use Outlook Object model and remove menu item and\or any other customization that belongs to add-in. Is it good scenario or there are better solutions?

Regards
matixsc  Wednesday, June 10, 2009 8:41 AM
Do you dynamically add this menu every time you Startup your addin code? Word has a scenario in Office 2003 to store menu settings in the active template but I don't believe this is the same in Outlook. Can you confirm if you have reset the command bars collection on the Shutdown event of your addin

Regards
Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
Mike Walker  Wednesday, June 10, 2009 5:23 PM

Hi,

First, here's the code in Shutdown:

 private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
 {            
       CheckIfMenuBarExists();
       RemoveToolbar();
 }

and code for called merhods is:

private void CheckIfMenuBarExists()
        {

            // If the menu already exists, remove it.
            try
            {
                Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
                    this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.
                    FindControl(Office.MsoControlType.msoControlPopup,
                    missing, menuTag, true, true);
                if (foundMenu != null)
                {
                    foundMenu.Delete(true);
                }

            }
            catch (Exception ex)
            {
                 StaticVariables.logger.writeError(ex);
                 MessageBox.Show(ex.Message);
            }
        }



public bool RemoveToolbar()
        {
            try
            {
                //if (_application.ActiveExplorer() != null)                
                if(this.Application.ActiveExplorer() != null)
                {
                    //get the CommandBar Collection
                    System.Collections.IEnumerator enumCommandBar = this.Application.ActiveExplorer().CommandBars.GetEnumerator();
                    enumCommandBar.MoveNext();
                    while (enumCommandBar.Current != null)
                    {
                        Office.CommandBar cmdBar = (Office.CommandBar)enumCommandBar.Current;
                        if ((cmdBar.Name.ToUpper() == "<Name of my cmdBar>"))
                        {
                            cmdBar.Delete();

                        }

                        enumCommandBar.MoveNext();
                    }
                }
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }

Regards

matixsc  Thursday, June 11, 2009 7:13 AM

Are you saying this is how you solved it as I said to put in the Shutdown Event?

Regards


Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
Mike Walker  Thursday, June 11, 2009 12:20 PM

Hi Mike,

This is existing code that does not solve the problem!

If I remove add-in using Outlook (COM Add-Ins|Remove), it works fine, but if I try to uninstall add-in using Add or Remove Programs from control panel, my customtop levelmenu item is still there.


Regards

matixsc  Thursday, June 11, 2009 12:34 PM
Here is a function I use, I pass the Reference to the CommandBar I used when I created the command bar on the dispose/Shutdown event.

private void UnBuildCommandBar(object cmdbar)
        {
            try
            {
                if (cmdbar != null)
                {
                    MSOffice.CommandBarPopup popup = cmdbar as MSOffice.CommandBarPopup;
                    MSOffice.CommandBar bar = cmdbar as MSOffice.CommandBar;

                    if (popup != null)
                    {
                        foreach (MSOffice.CommandBarControl t in popup.Controls)
                        {
t.Delete(true); } } else if (bar != null) { foreach (MSOffice.CommandBarControl t in bar.Controls) { t.Delete(true); } } } } catch { } }
This will delete all child items in the command bar you pass to the Function and then remove the toolbar.

Regards
Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
Mike Walker  Thursday, June 11, 2009 1:24 PM

Hi,

Here's the new version of Shutdown method:

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {            
            //CheckIfMenuBarExists();
            //RemoveToolbar();

            Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
                    this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup,missing, menuTag, true, true);

            UnBuildCommandBar(foundMenu);
        }


but I can't remove top level menu item after uninstall.

Regards

matixsc  Friday, June 12, 2009 8:26 AM
check whether your 'ThisAddIn_Shutdown' event is firing if you close outlook..
jaz.jaz  Friday, June 12, 2009 11:46 AM
The code within Shutdown method was executed byremoving add-in from COM Add-ins list!
I'm not sure what's happening with this code when you use Add\Remove Programs in control panel since top level menu item does not remove from main menu bar!(?)

Regards
matixsc  Tuesday, June 16, 2009 7:33 AM
I'm not sure what's happening with this code when you use Add\Remove Programs in control panel

The code will not execute if you uninstall your addin .

Your custom menu must be removed when you close the outlook not when you uninstall the application. Just check Addin_shutdown event is firing when you close outlook

jaz.jaz  Tuesday, June 16, 2009 1:08 PM

ThisAddIn_Shutdown event has been fired, but I’m getting an β€œObject reference not set to an instance of an objectβ€?error in this method and called methods as well.

Here's the latest version of the code:

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            CheckIfMenuBarExists();
            RemoveToolbar();

            try
            {
                Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
                        this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup, missing, menuTag, true, true);

                UnBuildCommandBar(foundMenu);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    StaticVariables.logger.writeInfo(ex + Environment.NewLine + ex.InnerException.Message);
                }
                else
                {
                    StaticVariables.logger.writeError(ex);
                }
            }
        }
So, if I close Outlook and uninstall add-in using Add Remove Programs, top level manu item does not removes from outlook. Everything is removed only if I use COM Add-Ins remove optionfrom Outlook.

Regards
matixsc  Friday, June 19, 2009 8:33 AM
Hi

In outlook 2007 the latest SP has some new code to improve the Shutdown speed and as such your code may not always be firing as the Outlook Object Model no longer cares for the 3rd Party Addins as much as a lot were holding outlook to keep open and not shutdown properly.

This article explains http://msdn.microsoft.com/en-us/library/dd239276.aspx


Regards

Mike
Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
Mike Walker  Friday, June 19, 2009 8:48 AM
Hi everyone,

I seem to have the same problem! Does anyone know of a solution yet?

With kind regards,

Bert Mulder.
JB Mulder  Thursday, July 16, 2009 7:42 PM

Hi!

Actually it's a good policie toremove the menu bar first then create each time the Addin startup

Bellow is some code from one of my addins

private Office.CommandBar menuBar;
private Office.CommandBarPopup newMenuBar;
private Office.CommandBarButton buttonArchiveFolder;
private Office.CommandBarButton buttonGetItems;
private Office.CommandBarButton buttonSearchArchive;
private string menuTag = "AUniqueTag";

private void ThisAddIn_Startup(object sender, System.EventArgs e)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€RemoveMenubar();
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€AddMenuBar();
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}


private void AddMenuBar()
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€try
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Office.MsoControlType.msoControlPopup, missing,
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€missing, missing, false);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€if (newMenuBar != null)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€newMenuBar.Caption = "Menos&3 OA";
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€newMenuBar.Tag = menuTag;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€//
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonArchiveFolder = (Office.CommandBarButton)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€newMenuBar.Controls.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Add(Office.MsoControlType.msoControlButton, System.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Type.Missing, System.Type.Missing, 1, true);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonArchiveFolder.Style = Office.MsoButtonStyle.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€msoButtonIconAndCaption;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonArchiveFolder.Caption = "Archive &Folder";
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonArchiveFolder.FaceId = 2499;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonArchiveFolder.Tag = "2";
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€this.buttonArchiveFolder.Click += this.buttonArchiveFolder_Click;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€//buttonArchiveAll.Picture = getImage();
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€//
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonGetItems = (Office.CommandBarButton)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€newMenuBar.Controls.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Add(Office.MsoControlType.msoControlButton, System.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Type.Missing, System.Type.Missing, 2, true);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonGetItems.Style = Office.MsoButtonStyle.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€msoButtonIconAndCaption;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonGetItems.Caption = "&Bring Items to PST";
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonGetItems.FaceId = 2188;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonGetItems.Tag = "3";
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonGetItems.BeginGroup = true;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€this.buttonGetItems.Click += this.buttonGetItems_Click;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€//buttonArchiveAll.Picture = getImage();
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€//
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€//
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonSearchArchive = (Office.CommandBarButton)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€newMenuBar.Controls.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Add(Office.MsoControlType.msoControlButton, System.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Type.Missing, System.Type.Missing, 3, true);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonSearchArchive.Style = Office.MsoButtonStyle.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€msoButtonIconAndCaption;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonSearchArchive.Caption = "&Search Archived Items";
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonSearchArchive.FaceId = 109;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonSearchArchive.Tag = "4";
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€buttonSearchArchive.BeginGroup = true;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€this.buttonSearchArchive.Click += this.buttonSearchArchive_Click;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€//buttonArchiveAll.Picture = getImage();

γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€newMenuBar.Visible = true;
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€catch (Exception ex)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€MessageBox.Show(ex.Message);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}

γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€private void RemoveMenubar()
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€// If the menu already exists, remove it.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€try
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€FindControl(Office.MsoControlType.msoControlPopup,
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€System.Type.Missing, menuTag, true, true);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€if (foundMenu != null)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€foundMenu.Delete(true);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€catch (Exception ex)
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€{
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€MessageBox.Show(ex.Message);
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€}

  • Edited byJoao LivioMVPThursday, July 16, 2009 9:29 PMCode not visible
  •  
Joao Livio  Thursday, July 16, 2009 9:28 PM
Hi Joao,

I allready had implemented this. First remove the CommandBar and than add the CommandBar.
But this doesn't take away the fact that the menuitem is still visible after de-installation.
For as far as I have found this is due to Outlook closing without waiting for custom add-ins to close.
Therefore when "ThisAddIn_ShutDown" is called, there is noreference to the Application object anymore and thus an exception is thrown.

The problem now is, how to call the ThisAddIn_ShutDown eventhandler before outlook is quit. I tried to catch the Application.Quit event, but than VS is telling me that "Quit" is ambiguis, because there is an event named Quit and a method named Quit().

Anyone? Help?

With kind regards,

Bert Mulder.
JB Mulder  Friday, July 17, 2009 8:37 AM
Its Still there !!!!

(headbang)

can any one has found solution for it, I tried lots of from this post too but (n)?

Thanks,
#Japan Shah

Japan Shah
  • Proposed As Answer byJB Mulder Friday, September 11, 2009 9:00 AM
  •  
shahjapan  Monday, August 24, 2009 7:24 AM

I have the same problem. I didn't implement RemoveToolbar() before Iran thedebugging from VS 2008. Now, there aremultiplesame menuitems on the top menu. Cannot remove them even I used Remove button In β€œCOM Add-insβ€?screen of Outlook.Any solution?

Thanks,
PJ

pjznotes  Tuesday, September 15, 2009 11:58 PM

I don't have a solution but I think I know what is causing this behaviour. The very first time my COM add-in was installed, WORD asked me to save the normal.dot file. This is where the issue is. Normal.dot saves changes to menus and toolbars, so it doesn't know that you've uninstalled your add-in. If you rename your normal.dot file then the menu should be gone. Don't know a better solution.


-RKS

rs199483  Wednesday, September 16, 2009 3:19 PM
In word the context of Normal is used to store the changes to the toolbars. The way around this is to check the normal.dot isn't Dirty by using the following logic;

If Application.NormalTemplate.Saved = FalseThen
' There maybe some changes that need to be saved in the database.
else
' The normal template has no changes to be saved.

' Apply the Commandbar changes you wish to do .

Application.NormalTemplate.Saved = False ' Set the Dirty state to False

End if

Regards
Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
Mike Walker  Wednesday, September 16, 2009 4:13 PM
The short answer, as Joao Livio is trying to say, is to create all of your CommandBars as temporary. Meaning you have to recreate them every time the add-in loads. If your add-in doesn't load,your custommenus and toolbars will never becreated, so there's nothing to clean up.

Never rely on uninstalling via the OS to do any cleanup for your Add-In. Similarly, any files or registry keys your add-in uses should be included and marked to be deleted on uninstall with your setup project.
Eric Legault: MVP (Outlook), MCTS (SharePoint) -- Owner, Collaborative Innovations (http://www.collaborativeinnovations.ca)
Eric Legault  Wednesday, September 16, 2009 5:07 PM
When I had this problem I just did the following:

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        Try
            For Each c As Office.CommandBarControl In Me.Application.ActiveExplorer().CommandBars.ActiveMenuBar.Controls
                If (c.Caption = menuTag) Then
                    c.Delete(True)
                End If
            Next
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub
If you just want to remove the garbage you left behind, you can add this information on your startup (create a new project on VS for Outlook Plugin - in this case, I used VB.NET), since if you enter it on shutdown it won't work (ActiveExplorer object doesn't exist anymore).

Ps: 'menuTag' is a string type. Then you have to declare it with the menu name to be deleted.

Regards.
Rafael Roballo  Friday, October 16, 2009 6:08 PM

You can use google to search for other answers

Custom Search

More Threads

• how to open powerpoint or excel through word using c#?
• I want to order an online version of Windows XP home
• Help with Outlook Object Model Guard...
• Download VSTO for 2003?
• Bundling Word addin with Outlook addin
• connecting to Oracle RDB database in VMS platform from VISIO reverse engineer
• row count and column count of excel file in C#
• VSTO Outlook Custom forms
• Error: "Cannot open project. ..."
• Edid the xml part of the currently active document