07 September 2007

Lets create Outlook 2007 Add-In using Visual Studio 2005.

If you have not installed VSTO then Download Microsoft Visual Studio 2005 Tools for Office Second Edition Runtime (VSTO 2005 SE) (x86).


Start IDE.

Click on File, New project

Select Outlook Add-In and Click on OK.

you will find some code like this:

Public
Class ThisAddIn
 Private WithEvents btn1 As Office.CommandBarButton

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

End Sub


Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

End Sub

End Class


Now add following code in StartUp event:

Dim explorer As Outlook.Explorer = Me.Application.ActiveExplorer()  

If explorer IsNot Nothing Then

Dim bar As Office.CommandBar = explorer.CommandBars.Add("saAction Bar", Temporary:=True)

bar.Visible = True

btn1 = bar.Controls.Add(Office.MsoControlType.msoControlButton, Temporary:=True)

btn1.Caption = "saAction Button"

btn1.Tag = "myOutlookAddin1.btn1"

btn1.Style = Office.MsoButtonStyle.msoButtonCaption

End If

And declare Button click event any where in the class.

 Private Sub Btn1_Click(ByVal ctrl As Office.CommandBarButton, ByRef cancelDefault As Boolean) Handles btn1.Click

MsgBox("Hi! this is VSTO")

End Sub


Done.

Now, Just run the project. Press F5, Outlook will automatically start and It will show a button there, and click on that button. See below "saAction Button" and messagebox.



Outlook is a very big application and using VSTO, you can utilize it's functions.

4 comments :

  1. Anonymous3:58 AM

    Hmmm, for me it doesn't work.

    Outlook 2007 launches, but there is no button, and none of my break points are hit.

    Chris

    ReplyDelete
  2. Anonymous10:17 PM

    Me too Chris

    I am using C#

    ReplyDelete
  3. I'm running it in VS 2008 and it works fine

    ReplyDelete
  4. the font is unreadable on your page.

    ReplyDelete