Solved

CommandBarControl.delete() not working as expected

Posted on 2011-02-16
3
720 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

770 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