Introduction
VSTO application add-ins allows developers to extend Office applications. Visual Studio Tools for Office (VSTO) is a set of development tools available in the form of a Visual Studio add-ins (project templates).
Many people don't know about VSTO. Let's learn the basic details of VSTO.
What is VSTO
VSTO is a platform to develop Office applications. Visual Studio Tools for Office (VSTO) is a set of development tools available in the form of a Visual Studio add-in (project templates) and a runtime that allows Microsoft Office 2003 and later versions of Office applications to host the .NET Framework Common Language Runtime (CLR) to expose their functionality via the .NET type system.
How to create Add-Ins using VSTO
Before you start to create Add-Ins using VSTO, please ensure prerequisites for creating Add-Ins using VSTO.
Prerequisite to run the downloaded sample
Develop/Build against Office 2010 |
Develop/Build against Office 2010 |
.Net Framework Version |
Visual Studio |
VSTO 4.0 |
Word, Excel, Outlook, PowerPoint, Visio, InfoPath, Project |
.NET 3.5 or 4.0 |
Built into Visual Studio 2010 Professional and above |
What is a Ribbon Control
If you are new to VSTO development, I am giving you a brief introduction to the Ribbon Control in Office type projects.
The Ribbon is a way to organize related commands (in the form of controls) so that they are easier to find. Controls are organized into groups along a horizontal strip at the top edge of an application window.
You can create your own Ribbon tabs and groups to give user's access to functionality that you provide in an application-level add-in.
What is the output of my Word Add-Ins
In this article, I am creating simple Add-Ins. This Add-In displays the current time while clicking on the ShowTime Ribbon Control. Let's have a look at the detailed procedure.
- Create New project in VS 2010
Create a new project and select "Project Type Office and Word 2010 Add-in". Give a name for your project add-ins as shown in the following screenshot.
- Create Ribbon
Right-click on your project's Solution Explorer and click on "Add New Item" and select "Ribbon (Visual Designer)" in the item list.
Give a name of your Ribbon Control and click on the "Add" button. You will see that in the following screenshot.
- Add Office Ribbon Control form ToolBox
Once you have added your Ribbon Control, open the ToolBox from Visual Studio. You will see various tools in the ToolBox. There is a default Ribbon Group control available on your Ribbon as shown in the following screenshot.
Choose "Label control" from the Office Ribbon Control from the Toolbox and drag and drop this label control into the group control of your Ribbon. Give an appropriate name for your controls.
- Add a Windows Forms form in the Office Ribbon Control
We need to show the current time while clicking on the ShowTime button. So, here I am using a Windows Forms form to show the current time.
Right-click on your project and seelct "Add new item" from the menu. Select "Windows Form".
- Once you have added a Windows Forms form to your project, click on the Windows Forms form and add two labels. The first one is a caption label and the second label shows the current time value. Provide a meaningful full name for the label and form control. You will see that in the following screenshot.
On your Windows Forms form, please add code to display the current time in the form load event.
lblCurrentTimeVal.Text = DateTime.Now.ToShortTimeString();
- Double-click on your Ribbon control button, you will get a click event of the ribbon control. Write the following code to show our Windows Forms form.
private void btnClock_Click(object sender, RibbonControlEventArgs e)
{
frmShowTime frmTime = new frmShowTime();
frmTime.Show();
}
- Build and run your Add-Ins project. You will see a new ribbon add-in with "MyFirstAdd Ins" in your Word document as shown in following screen shot.
- Click on the "ShowTime" Ribbon button. You will see the current time in our Windows Forms form as shown in the following screenshot.
Reference Link: http://msdn.microsoft.com/en-us/library/d2tx7z6d(v=vs.100).aspx