Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Outlook 2007 Add-in Using Microsoft Visual C#.NET

, 24 Feb 2010
Rate this:
Please Sign up or sign in to vote.
Outlook 2007 add-in using Microsoft Visual C#.NET

Table of Contents

Introduction

Many well known companies use the Microsoft Office System to operate their business. Microsoft Office system is both strong and powerful to operate your business information, but sometimes you may need some extra features into your Office system so that you can do some more complex tasks efficiently. That is the reason to build custom solutions and add-ins for Microsoft Office. Using Microsoft Visual Studio 2005 / 2008 Tools for the Microsoft Office System (VSTO), you can develop custom solutions to help solve the problems that your business needs to solve.

What We Learn

This article demonstrates how to develop an add-in for Microsoft Office Outlook 2007 to help a fictitious company. You will learn how add custom menus, toolbar command button, custom tabs (Outlook 2007), work with ribbon and custom forms as well.

Well… I hope that you are enjoying; let’s start. I try to categorize it into two parts as listed below:

Part - A

  1. We will discuss basic concepts how to build your first custom add-in for Office Outlook 2007.
  2. We will discuss how to add a custom menus, toolbar command button, custom tabs (Outlook 2007).

Part - B

This part is not included yet…. I hope that this will be available in the next part.

  • We will discuss how to work with different types of Outlook objects such as email, appointments, task, etc.

Basic Overview of Outlook 2007 Add-In

Develop an Outlook 2007 add-in using Microsoft Visual Studio .NET Framework 3.5, Microsoft Office System provides a basic Template for doing this. The templates are available in both Visual Basic and Visual C# languages. Each template includes the OutlookItem class, which enables developers to work with generic Outlook items through late-binding, without determining the item type first.

More information can be found at this link.

Outlook Object Model Overview

To develop add-ins for Microsoft Office Outlook, you can interact with the objects provided by the Outlook object model. The Outlook object model provides classes that represent items in the user interface. For example, the Microsoft.Office.Interop.Outlook.Application class represents the entire application, the Microsoft.Office.Interop.Outlook.MAPIFolder class represents a folder that contains e-mail messages or other items, and the Microsoft.Office.Interop.Outlook.MailItem class represents an e-mail message.

More information can be found at this link.

Build Your First Add-In for Outlook 2007 (Part - A)

In this section, we will discuss about creating your first add-in for Outlook 2007. Microsoft Visual Studio provides the template for creating an add-in for Microsoft Office system.

How to Create an Add-In project for Microsoft Office Outlook 07

To create a new Outlook 2007 Add-In project, we need to follow the step(s) listed below:

  • Open Microsoft Visual Studio .NET and create a new project by selecting “Project” menu under the File > New menu.
Figure - (i)

CreateProjectStep-1

Figure (i) shows how to create a project using Microsoft Visual Studio 08.

  • A project type window will popup with the available language and available templates.
  • Select C# > Office > 2007 from the project type tree.
  • You will find the available templates, select Outlook 2007 add-in & finally enter your project name and click the Ok button for creating the project.
Figure - (ii)

CreateProjectStep-2

Figure (ii) shows the available Template to create an add-in project for Office system.

Create Your First Custom Controls & Events

In this section, we will discuss how to add custom menus, toolbar command buttons, etc. For this purpose, we use the following:

  1. Office.CommandBar
  2. Office.CommandBarPopup
  3. Office.CommandBarButton

Create a Custom Menu

This example below creates a Menu called “My Menu” in Microsoft Office Outlook 2007. Figure (iii) show the menu in your Outlook 07.

Figure - (iii)

CustomMenu

Code Snippets

 #region "Outlook07 Menu"
        private void MyMenuBar()
        { this.ErsMyMenuBar();
           try
            {
                //Define the existent Menu Bar
                _objMenuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                //Define the new Menu Bar into the old menu bar
                _objNewMenuBar = (Office.CommandBarPopup)
                                 _objMenuBar.Controls.Add
                (Office.MsoControlType.msoControlPopup
                                                        , missing
                                                        , missing
                                                        , missing , false);
                if (_objNewMenuBar != null)
                {
                    _objNewMenuBar.Caption = "My Menu";
                    _objNewMenuBar.Tag = menuTag;
                    _objButton = (Office.CommandBarButton)_objNewMenuBar.Controls.
                    Add(Office.MsoControlType.msoControlButton, missing,
                        missing, 1, true);
                    _objButton.Style = Office.MsoButtonStyle.
                        msoButtonIconAndCaption;
                    _objButton.Caption = "My menu item.";
                    //Icon 
                    _objButton.FaceId = 500;
                    _objButton.Tag = "ItemTag";
                    //EventHandler
                    _objButton.Click += 
           new Office._CommandBarButtonEvents_ClickEventHandler(_objButton_Click);
                    _objNewMenuBar.Visible = true;
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString()
                                                   , "Error Message");
            }        }
        #endregion

Create a Custom Toolbar

This example creates a toolbar command button called “My ToolBar Button” in Microsoft Office Outlook 2007.
Figure (iv,v) shows the toolbar in your Outlook 07.

Figure - (iv)

CustomCommandButton

Figure - (v)

ToolBar

Code Snippets

private void MyToolBar()
        {   try
            {
                // Delete the existing instance, if applicable.
                Office.CommandBar _objTmpToolBar = 
        (Office.CommandBar)this.Application.ActiveExplorer()
                    .CommandBars.FindControl(missing, missing,
                   menuToolBarTag, true);
                if (_objTmpToolBar != null)
                    _objTmpToolBar.Delete();     // Add a new toolbar to the 
                    // CommandBars collection
                                // of the Explorer window.
                _objToolBar = this.Application.ActiveExplorer()
                    .CommandBars.Add(menuToolBarTag,
                    Office.MsoBarPosition.msoBarTop, false, true);
                if (_objToolBar != null)
                {
                    // Add a button to the new toolbar.
                    _objNewToolBarButton = (Office.CommandBarButton)_objToolBar
                        .Controls.Add(Office.MsoControlType.msoControlButton,
                        missing, missing, 1, true);
                    _objNewToolBarButton.Style = Office.MsoButtonStyle
                        .msoButtonIconAndCaption;
                    _objNewToolBarButton.Caption = "My ToolBar Button";
                    _objNewToolBarButton.FaceId = 65;
                    _objNewToolBarButton.Tag = menuToolBarTag;
                    _objNewToolBarButton.Click += 
           new Office._CommandBarButtonEvents_ClickEventHandler
            (_objToolBarButton_Click);
                    _objNewToolBarButton.Visible = true;
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString()
                                                   , "Error Message");
            }        
}      

Conclusion

I hope that this may be helpful to you. Enjoy!

References

  • MSDN

History

  • 23rd February, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Md. Marufuzzaman
CEO
Bangladesh Bangladesh
A highly experienced leader with successful track record of software development, product innovations, brand management and corporate communication etc. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by codeproject.com and also selected as a mentor of codeproject.com. Published over 100 technical articles in various software development resource sites (i.e., codeprojetc.com, Microsoft MSDN, and IEEE & IBM (In progress)) and various IT Forums, Blogs etc.
 
Over ten years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, development, services, data management and analytics, customer experience management, content services, digital analytics and optimization.
 
An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint. Believes in transparency, commitment and teamwork.
 
Expertise: Software/Solution Architect, SaaS platform base application, Large scale win32/web based business software solutions, enterprise applications, integration, etc.
 
Technologies/Tools: Microsoft.Net version 05/08/10/12, Microsoft SQL Server version 7/2K/05/08/12 , Oracle version 10/11, MySql version 5.1, 5.5, PS2, Visual C#, R, VB.NET, ASP.NET, PHP, API, MVC, WebAPI , Add-In Visual Basic etc.,. I have also more than two years’ of strong experience in mobile-VAS (platform development).
 
Points of Interest: Technology and research & development especially focused on business functionalities and social business areas as well, few stuff including:
 
1.R&D on new techniques as required to increase business revenue.
2.Urban and rural sectors to improve people’s lifestyle, better medical facilities, education, social business etc., using innovative technical solutions.
3.Research and innovative product development.
4.Etc.
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionUrgent Pinprofessionalkiranwilson12-Aug-14 1:06 
GeneralRe: Urgent PinmentorMd. Marufuzzaman12-Aug-14 5:34 
QuestionUrgent Pinmemberumeshfaq3-Oct-13 23:52 
AnswerRe: Urgent PinmentorMd. Marufuzzaman12-Aug-14 5:38 
QuestionVisio custom menu event problem Pinmemberhimanshub197813-Sep-13 0:58 
QuestionCreating Secured Email PinmemberJanieDsz26-Jun-13 6:42 
AnswerRe: Creating Secured Email PinmentorMd. Marufuzzaman26-Jun-13 6:51 
QuestionHow to Create Form Regions using outlook 2003 add-in in vsto 2008 PinmemberDEEPIKAP116-Jun-13 22:15 
QuestionNeed urgent help with commandbar combobox Pinmemberumeshfaq23-May-13 18:48 
AnswerRe: Need urgent help with commandbar combobox PinmentorMd. Marufuzzaman24-May-13 7:55 
GeneralRe: Need urgent help with commandbar combobox Pinmemberumeshfaq26-May-13 18:25 
GeneralRe: Need urgent help with commandbar combobox Pinmemberumeshfaq30-May-13 19:50 
GeneralMy vote of 1 Pinmembermaddinthegreat11-Dec-12 13:42 
GeneralRe: My vote of 1 PinmentorMd. Marufuzzaman12-Dec-12 4:09 
GeneralRe: My vote of 1 PinprofessionalBrisingr Aerowing24-Aug-13 13:21 
GeneralMy vote of 3 PinmemberIngar Tødenes31-Oct-12 4:43 
QuestionApplication for outlook ribbon PinmemberSid_ga23423-Oct-12 4:09 
QuestionHi PinmemberMP TP4-Apr-12 2:37 
AnswerRe: Hi PinmentorMd. Marufuzzaman4-Apr-12 3:29 
Question"Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.TaskItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063035-0000-0000-C000-000 Pinmembertaneem785130-Jan-12 6:52 
Questionoutlook 2010 addin Pinmemberrtalsaniya12-Dec-11 3:49 
AnswerRe: outlook 2010 addin PinmvpMd. Marufuzzaman12-Dec-11 4:24 
Hi,
I'm not sure, I think you can't.
Thanks
Md. Marufuzzaman


I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

GeneralAdd HowTo put element in an existing menu Pinmemberserup9-Jun-11 20:25 
GeneralRe: Add HowTo put element in an existing menu PinmvpMd. Marufuzzaman9-Jun-11 20:48 
GeneralRe: Add HowTo put element in an existing menu Pinmemberserup9-Jun-11 20:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140921.1 | Last Updated 25 Feb 2010
Article Copyright 2010 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid