Introduction

I assume you have a rudimentary plug-in up and running because I won't show you how to actually create a plug-in in this article. There are plenty of good articles out there covering this topic. Since all Office applications share the same commandbars, this article applies to other Office products as well.

Overview of the CommandBar Objects

Let us take a brief look at how the structure of the Commandbar Objects looks like:

What gives us a little trouble is the fact that all parameters are accepting objects. Let's examine the parameters in more detail and what type it expects:

object name -> string name

The name of the new Command Bar.

object position -> MsoBarPosition position

The position of the command bar. Expects a value from the MsoBarPosition enumeration. msoBarLeft, msoBarTop, msoBarRight, msoBarBottom indicate the left, top, right, and bottom coordinates of the new command bar. msoBarFloating indicates that the new command bar won't be docked. msoBarPopup indicates that the new command bar will be a shortcut menu. msoBarMenuBar applies to Macintosh only.

object menubar -> bool menubar

true to replace the active menu bar with the new command bar. The default value is false.

object temporary -> bool temporary

true to make the command bar temporary. Temporary command bars are deleted when the container application is closed. The default value is false.

The type of the control. Expects a value from the MsoControlType Enumeration.

object id -> int ID

An integer that specifies a built-in control. If the value is 1, or if omitted, a blank custom control of the specified type will be added to the command bar. You can omit a value by using the Missing.Value property from the System.Reflection namespace, otherwise simply use 1;

object parameter -> object parameter

This parameter works like the "TAG" property of normal Windows controls. You can store any user defined data here or simply omit the parameter.

object before -> int before

A number that indicates the position of the new control on the command bar. The new control will be inserted before the control at this position. If omitted, the control is added at the end of the command bar.

object temporary -> bool temporary

true to make the command bar temporary. Temporary command bars are deleted when the container application is closed. The default value is false.

Conclusion

Hopefully, this article was helpful for you. I am looking forward to your feedback.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

The problem is, when I fill text1 and then I click on text2 textbox, the text of text1 just disappear. When rather then click the textbox I move the focus by pressing TAB key then the content of text1 doesn't dissapear.

I think it's a focus problem, any idea? Is there any other way to add a TextBox to the CommandBar?

Dear Sir,
I use the commandbars to create serval commandbutton on the tools in outlook.
But how to use the commandbar to add a split?
I try to find the commandbar control, but it always fail.
Could you lead me how to create it?
Thanks.

Do you wana add split on a dropdown menu ? If Yes then , on CommandBarControl object use property "BeginGroup" and make it true;
for example
CommandBarControl newbarcontrol = newbar.Controls.Add(MsoControlType.msoControlButton,,,);
now
newbarcontrol.BeginGroup = true;
thats it.

All the posted msgs are good and very informative. I have added the addin in MS Outlook 2003 using VSTO for VS2005. My this created addin is displayed in main interface of MS Outlook but I want to add that in its child window i.e. New Mail Window. Please guide me that how can I get Outlook's child window in order to add the addin.

Moreover, I want to get the event of Send/Receive button. How this thing will be possible?

If you create a button variable that goes out of scope before your add in goes away, garbage collection will destroy the button and your click event will go bye-bye. What is really cool is that it will work for a little while and then all the sudden stop.

Moral of the story: Make your CommandBarButton vars as fields in the add in then they will not go out of scope until the addin is disposed.

How can we add a new Tab to the Meeting/Appointment to capture my add-in specific stuff(scheduling a conference).
I need to use the data in the "To", "Subject", "Schedule" filed along with the information in the new Tab I will be creating.

I need to write an add-in using C# to aceive the above.
I did read up the article on writing an add-in using C#, but I am totally new to GUI programmaing on windows platform.

I see you post is from 2005, so I am wondering if you already developed your addin because I'm looking to do something closed to what you had to do. If you got information or if you can share you code It will sure be of great help for me.

Hi
I am using Microsoft.office.core (11.0) com library. I have added new button to the outlook toolbar. If i click on that it should get the currently focused email detals(as like if i click on Reply,Forward etc...). I am able to get the entire folder emails detail but not exactly the selected email.

Hi
I am using Microsoft.office.core (11.0) com library. I have added new button to the outlook toolbar. If i click on that it should get the currently focused email detals(like if i click on Reply,Forward etc...). I am able to get the entire folder emails detail but not exactly the selected email.

1st of all, I have to tell that i love your code... it helped me out a lot, but
there's something strange in my system here. I just cannot bring this CommandBar
to appear in my Outlook. I'm struggling a whole day long without success.
All the other parts like Popup menus/sub menus are functioning, out of that commandbar.

Question: have you ever faced with such issues ?
(if yes what would be the solution?)

Thanks for this great article! I have a request, if I may - could you please guide me towards some of the "plenty of good articles out there" about starting a basic Outlook plug-in in C#. Thank you very much for your time!