Click here to Skip to main content
15,170,331 members
Articles / Programming Languages / C#
Posted 10 Dec 2005


55 bookmarked

Build Your Own Add-in For Microsoft Office Using .NET

Rate me:
Please Sign up or sign in to vote.
3.68/5 (12 votes)
10 Dec 20052 min read
How to build an add-in for Microsoft applications supporting add-ins, using C#.

Sample image


In this article, we will learn how to create a simple Hello World browser add-in for Microsoft’s applications that supports add-in. A list of such applications is given here:

  1. Microsoft Word
  2. Microsoft VSMacros IDE
  3. Microsoft Visual Studio .NET
  4. Microsoft Visio
  5. Microsoft Publisher
  6. Microsoft Project
  7. Microsoft PowerPoint
  8. Microsoft Outlook
  9. Microsoft FrontPage
  10. Microsoft Excel
  11. Microsoft Access

In this article, we will take Microsoft Outlook as an example.


You must have the following …

  1. Microsoft Development Environment 2003 or higher
  2. Microsoft .NET Framework 2.0
  3. Office Primary Interop Assemblies (PIAs). For Office XP, click here to download.

Creating the Add-in

  • Run the Microsoft Development Environment.
  • Go to File> New Project>, a dialog will appear.
  • Go to Other Projects> Extensibility Project, select Shared Add-in type project template.

Add-In Wizard

When the Add-in wizard starts, press Next...

Sample image

Select programming language (example C#), press Next.

Sample image

Select applications in which you want to host your add-in, press Next.

Sample image

Provide add-in name and description, press Next.

Sample image

Choose add-in options, press Next.

Sample image

Press Finish.

Sample image

Setup Projects

Two projects will be added automatically.

  1. Add-in project.
  2. Setup project.

Creating the Browser Form

  1. Add a form for the Add-in project, named frmHelloWorld.cs.
  2. Add a Label, TextBox, and a PictureBox.
  3. Add a Microsoft web browser control to the form (you can get it by right clicking on the toolbox, selecting Add/Remove Items, and clicking on the “COM Components”: a lot of controls will be listed, select Microsoft Web Browser Control, and press OK.
  4. With the following code, create a function go():
void go()
        stbPanel1.Text="Trying to open "+tbURL+"..." ;
        object obj=new object ();
        browser.Navigate(tbURL.Text,ref obj,ref obj,ref obj,ref obj);
    catch(Exception ex)
        //error hanlder here......

Call this function on the PictureBox's Click event.

Programming for Add-in Connection

Install PIAs and add a reference to the following DLL: Microsoft.Office.Interop.Outlook.DLL.

Sample image

There will be a file connect.cs in the add-in project, open it. Declare the following items globally:

//for Outlook Express you can mention here word, power point. 
private Microsoft.Office.Interop.Outlook.Application applicationObject; 
private object addInInstance; 
private CommandBarButton btnLaunch;

In the function OnStartupComplete, write the following code:

public void OnStartupComplete(ref System.Array custom)
    CommandBars commandBars = 

        //if will be good if button exist use it
               btnLaunch= (CommandBarButton)
        //if error occur
                 btnLaunch = (CommandBarButton)
        btnLaunch.Caption = "Hello World Browser!";
        btnLaunch.Style = MsoButtonStyle.msoButtonCaption;
    //use tag for quick access of button.
    btnLaunch.Tag = "This is Hello World Browser!";

    btnLaunch.OnAction = "!<EMAILSTATSADDIN.CONNECT>";
    btnLaunch.Visible = true;
    btnLaunch.Click += new 

In the function OnBeginShutdown, write the following code:

public void OnBeginShutdown(ref System.Array custom)
    //delete our button...
    CommandBars commandBars = applicationObject.ActiveExplorer().CommandBars;
        //remove on unload...
    catch(System.Exception ex)
        //code to show/log error...

Write the following code in the btnLanuch event handler:

private void btnLaunch_Click(CommandBarButton Ctrl, 
                            ref bool CancelDefault)
        frmHelloWorld objfrmHelloWorld=new frmHelloWorld ();
    catch(Exception ex)
        //code to show or log error...

Rebuild and Installation

Right click on the setup project, click Rebuild, and it will automatically rebuild the add-in and the setup project. Then, right click on the setup project and click Install.


Run Microsoft Outlook, and you will see “Hello World Browser!” on the toolbar. Click on it and your add-in will start. As you can see here...

Sample image

Known Issues

After uninstallation, the “Hello World Browser!” button is not removed from the Outlook toolbar.


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.

A list of licenses authors might use can be found here


About the Author

Mubi |
Business Analyst Valentia Technologies
Ireland Ireland

Comments and Discussions

Questionhow to register com add in in local machine with class library project. Pin
Sourabh111128-Nov-16 5:54
MemberSourabh111128-Nov-16 5:54 
QuestionActiveX control for VBA form created in C# Pin
Petr Slezák18-Feb-16 5:06
MemberPetr Slezák18-Feb-16 5:06 
QuestionHow to in Outlook Web Access page? Pin
tiger200522-Feb-10 7:38
Membertiger200522-Feb-10 7:38 
GeneralHelp, How to: Create menu on MenuBar when click New/Mail Message Pin
nguyennhutoan03ct3-Jul-07 0:44
Membernguyennhutoan03ct3-Jul-07 0:44 
GeneralAddIn Deployment Pin
nguyennhutoan03ct27-Jun-07 23:30
Membernguyennhutoan03ct27-Jun-07 23:30 
AnswerRe: AddIn Deployment Pin
Mubi | www.mrmubi.com28-Jun-07 0:14
professionalMubi | www.mrmubi.com28-Jun-07 0:14 
GeneralExcel Pin
Sergey Gorchichko7-Feb-07 5:18
MemberSergey Gorchichko7-Feb-07 5:18 
Questiondiasymreader.dll problem Pin
al866-Dec-06 23:37
Memberal866-Dec-06 23:37 
QuestionAssembly Office 11.0 Pin
Eckhart471116-Sep-06 1:09
MemberEckhart471116-Sep-06 1:09 
AnswerRe: Assembly Office 11.0 Pin
Mubi | www.mrmubi.com17-Sep-06 20:17
professionalMubi | www.mrmubi.com17-Sep-06 20:17 
QuestionDocking?? Pin
Green Egg Weasel Boy26-Jun-06 17:07
MemberGreen Egg Weasel Boy26-Jun-06 17:07 
AnswerRe: Docking?? Pin
AndySummer25-Jan-07 21:41
MemberAndySummer25-Jan-07 21:41 
GeneralIn PowerPoint the button event is not firing. Pin
Anil_gupta5-Jun-06 5:25
MemberAnil_gupta5-Jun-06 5:25 
GeneralExcel Worksheet Function Pin
chrisv16-Mar-06 14:17
Memberchrisv16-Mar-06 14:17 
QuestionHow do i debug???? Pin
rajiv40422-Jan-06 2:10
Memberrajiv40422-Jan-06 2:10 
AnswerRe: How do i debug???? Pin
Mubi | www.mrmubi.com22-Jan-06 19:04
professionalMubi | www.mrmubi.com22-Jan-06 19:04 
GeneralI got the correct .dll now Pin
halifaxdal21-Dec-05 5:21
Memberhalifaxdal21-Dec-05 5:21 
QuestionHow to add reference Pin
halifaxdal21-Dec-05 5:04
Memberhalifaxdal21-Dec-05 5:04 
AnswerRe: How to add reference Pin
Mubi | www.mrmubi.com21-Dec-05 18:49
professionalMubi | www.mrmubi.com21-Dec-05 18:49 
GeneralOutlook button bar Pin
bsieber11-Dec-05 3:05
Memberbsieber11-Dec-05 3:05 
GeneralRe: Outlook button bar Pin
Mubi | www.mrmubi.com11-Dec-05 18:13
professionalMubi | www.mrmubi.com11-Dec-05 18:13 
GeneralRe: Outlook button bar Pin
eligazit22-Dec-05 21:36
Membereligazit22-Dec-05 21:36 

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

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