Solved

CommandBarControl.delete() not working as expected

Posted on 2011-02-16
3
731 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

737 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