Introduction
VSTO application add-ins allow developers to extend Office applications. Visual Studio Tools for Office (VSTO) is a set of development tools available in the form of 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 for developing 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 the 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 users 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.
Step 1. 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.
Step 2. Create Ribbon
Right-click on your project's Solution Explorer click on "Add New Item" and select "Ribbon (Visual Designer)" in the item list.
Give the name of your Ribbon Control and click on the "Add" button. You will see that in the following screenshot.
Step 3. Add Office Ribbon Control from 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.
Step 4. Add a Windows Forms formin 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 select "Add new item" from the menu. Select "Windows Form".
Step 5. 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();
Step 6. Double-click on your Ribbon control button, and 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();
}
Step 7. 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 the following screenshot.
Step 8. 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