Click here to Skip to main content
13,258,007 members (77,018 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 7 May 2011

Justin‘s VSTO Knowledge Base: 01, First VSTO Application

, 7 May 2011
Rate this:
Please Sign up or sign in to vote.
Justin‘s VSTO Knowledge Base: 01, First VSTO Application

First, let me introduce my development environment. I’m using Visual Studio 2010 with Office 2010 and all my VSTO applications are basing on VSTO 4.0 and .NET Framework 4.0. All my demo code is based on them and if you are using VS 2008, you can port this code to VS2008 very easily. The only thing that you need take care of is that there are two new features in .NET Framework 4.0, dynamic types and optional parameters, which are widely used in VSTO 4.0. (You can Google these features and I’m not going to talk more about them in the article??.)

Create VSTO Project

Build Development Environment

It’s easy to build a development environment for VSTO. Microsoft does a excellent job. You just need to install Visual Studio 2010 with VSTO 4.0 and Office 2010 for building VSTO application.

Create Project

Choose New Project->C#->Office->Word 2010 Add-in (Please check image below):

Create New Project

From this image, we know that there are other two types of project, Word 2010 Document and Word 2010 Template besides Word 2010 Add-in. Their difference is that the Add-in project will create an Application level add-in and every time when Word is starting up, Word will load this add-in, but Document project and Template project are Document Level projects. They will create Word files and the code will only be loaded and executed when a particular Word document is opened by the end user. (Document project will create .docx file and Template project will create .dotx file)

Add Customized Ribbon

Right click project –>Add new item->Office->Ribbon (Visual Designer):


Add a new button on Ribbon and name it Hello.


Double click Hello button and add this code in btHello_Click method:

1:         private void btHello_Click(object sender, RibbonControlEventArgs e)
2:         {
3:             System.Windows.Forms.MessageBox.Show("Hello World!");
4:         }

Press F5 to run the current Project and Visual Studio will help you to start up a new Word instance. Click Add-ins tab in Ribbons and click Hello button. If you see the Hello World! message box, then your first VSTO application is done, Congratulations!


Let’s make some change for our first VSTO application. From the last screenshot, we find that our customized Ribbon is along with Ribbons from other Add-in in the same Ribbon Tabs. Now we want to make our Ribbon independent. In Visual Studio, please open Ribbon Visual Designer and click Ribbon Tab (Check Image below). We change ControlIdType to Custom and ControlID to MyFirstAddin. In this way, our Ribbon will be loaded in a new Ribbon Tab, called MyFirstAddin.


* There is a small trick. If your boss wants you to insert the customized Ribbon to Office built-in tabs, we can also achieve this task. Just change the ControlIdType to Office and Set OfficeID as TabHome, please check image below:


Result screenshot:


You can get other OfficeIDs from here: Office 2010 IDs, Office 2007 IDs.

Add Task Pane

Create Task Pane

Task Pane is a useful control and it gives you a way to provide users with a familiar interface to access your solution’s features. First let’s create a User Control, which will be used in Task Pane. and our main features will be added in this user control. 1 UserControlForTP

Let's add a label on User Control first. (We won’t add more functions in this task pane this time.)

2 UserControlForTP View

In ThisAddIn.cs file, we will add this code. In this way, Task Pane will be displayed after Addin loads:

1:     public partial class ThisAddIn
2:     {
3:         public CustomTaskPane _MyCustomTaskPane = null;
5:         private void ThisAddIn_Startup(object sender, System.EventArgs e)
6:         {
7:             UCForTaskPane taskPane = new UCForTaskPane();
8:             _MyCustomTaskPane = this.CustomTaskPanes.Add(taskPane, "My Task Pane");
9:             _MyCustomTaskPane.Width = 200;
10:             _MyCustomTaskPane.Visible = true;
11:         }
13:         private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
14:         {
15:         }
17:         #region VSTO generated code
18:         // ……
19:         #endregion
20:     }

Result screenshot:

3 TaskPaneResult

Use Ribbon to control Task Pane

We have finished a Task Pane and we are going to use your customized Ribbon to control this Task Pane display. First, we will refine our Ribbon, add two buttons and add icons for buttons. Please check images below:

4 Ribbon

Create Onclick event for Open Task Pane and Close Task Pane:

1:         private void btnOpen_Click(object sender, RibbonControlEventArgs e)
2:         {
3:             if (Globals.ThisAddIn._MyCustomTaskPane != null)
4:             {
5:                 Globals.ThisAddIn._MyCustomTaskPane.Visible = true;
6:             }
7:         }
9:         private void btnClose_Click(object sender, RibbonControlEventArgs e)
10:         {
11:             if (Globals.ThisAddIn._MyCustomTaskPane != null)
12:             {
13:                 Globals.ThisAddIn._MyCustomTaskPane.Visible = false;
14:             }
15:         }

Run your project and check the result.


In this article, we learned the basic information about VSTO development, including Ribbon and Task Pane. The sample code can be downloaded here. In the following articles, I will show you more samples and more detailed information about VSTO development in Word, Excel and Outlook.

And if you have any questions, please email me at


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


About the Author

China China
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionRated 5 Pin
rht34115-Jan-15 2:59
memberrht34115-Jan-15 2:59 
GeneralMy vote of 5 Pin
Trip-l9-Nov-11 6:31
memberTrip-l9-Nov-11 6:31 
GeneralMy vote of 5 Pin
Mario Majcica8-May-11 11:25
memberMario Majcica8-May-11 11:25 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 7 May 2011
Article Copyright 2011 by izualx
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid