Solved

CommandBarControl.delete() not working as expected

Posted on 2011-02-16
3
712 Views
Last Modified: 2012-05-11
Testing out the CommandBarControl.Delete() method on addin_shutdown in a Word add-in app.

I want to add a button during startup and then delete it during shutdown. Problem happens when I rerun the addin application, I do a check to see if the CommandBarButton control is there and it always is.

The delete(false) procedure seems to remove the commandbarbutton from the commandbars collection, but when I restart the add-in to debug it reappears.

It is not working like I think it should. Does anyone have any suggestions as to how to properly dispose of a commandbarcontrol forever? I thought giving the delete method a temporary parameter of false would do the trick but not so.

Thanks in advance,
Mel
Microsoft.Office.Core.CommandBar cellbar;

  private void ThisAddIn_Startup(object sender, System.EventArgs e)
  {
   cellbar = Application.CommandBars["Text"];
   Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, "MYRIGHTCLICKMENU", missing, missing);
   if (button == null)
   {
    // add the button     
    button = (Microsoft.Office.Core.CommandBarButton)cellbar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, missing, missing, true);
    button.Caption = "My Right Click Menu Item";
    button.BeginGroup = true;
    button.Tag = "MYRIGHTCLICKMENU";
   }
  }

  private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
  {
   Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, "MYRIGHTCLICKMENU", missing, missing);
   object val = false;
   button.Delete(val);
  }

Open in new window

0
Comment
Question by:rotovibe
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34923454
Hi,
Please check out the conversation which helps to ur requirement.
http://social.msdn.microsoft.com/Forums/en/vsx/thread/8fff7d90-7867-4608-a8b6-ba9362d91411
0
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34923459

Check this notes on how to perform the actions by Carlos J. Quintero:
http://www.mztools.com/articles/2005/mz2005003.aspx
0
 
LVL 4

Accepted Solution

by:
jmdion earned 500 total points
ID: 34926269
I gave a quick look at my code for an add-in I wrote 2 years ago. This is what I understand/remember.

When you remove the CommandBarButton form the collection, it is not removed from Normal.dot.  All you can do is check if the button is present and make it hidden.

If you want more control then you must create you own Application.CustomizationContext by creating your own MyAddInName.dot file (and add it to the Templates collection).  You can create it and delete it at Startup() and ShutDown() if you don't want to confuse the users. This file will never be used as a real template but you need it anyway because you can't create a CustomizationContext without a template.  This is also better because there is less chance of interference if other addins store their customizations in Normal.dot or if Normal.dot becomes corrupt.

Besides the reference on MSDN Library on CustomizationContext, you can google for explanations on this topic by "Cindy Meister" or "Jonathan West".



0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now