What Is VSTO

Visual Studio 2005 Tools for Office (VSTO) enables you to extend Office 2003 applications—such as Word, Excel, InfoPath, and Outlook—using either Visual Basic 2005 or Visual C#. Instead of using Visual Basic for Applications (VBA) and the Visual Basic Editor (VBE) from within Office, you use the robust Visual Studio development environment to create your customizations. Whether you're creating a simple data entry application or complex enterprise solutions, VSTO makes it easy.

As the name suggests, VSTO is a toolset within Visual Studio for creating custom Office applications. To get the VSTO functionality in Visual Studio, you must install either the stand-alone edition of Visual Studio 2005 Tools for the Microsoft Office System or Visual Studio Team System.

To customize Office using VSTO, you start by creating a new Office project in Visual Studio. Five types of Office-related Visual Studio project templates are included in a default installation of VSTO: four project templates for creating document-level customizations for Word and Excel, and one project template for creating an application-level customization in the form of an Outlook add-in. VSTO also includes an optional template for InfoPath extensions. However, because this book is written for developers who are interested in moving from VBA to VSTO, InfoPath development is not described. InfoPath has never supported VBA and so a comparison cannot be made.

A document-level customization means that the code is associated with a particular document rather than the entire application. Keep in mind that the code does not reside in the document or a template, as is the case with VBA customizations. Instead, the code lives inside a code library called an assembly that is associated with the document. After you create a new VSTO project, you can access the objects in the Office object models via a primary interop assembly (PIA). The Office PIAs allow VSTO customizations to interact with the Office object model. You'll learn more about assemblies in Chapter 3, Introduction to Managed Code.

VSTO also provides enhanced Office objects that you can program against. For example, you'll find VSTO versions of an Excel workbook, worksheet, and range that have extended functionality not found in the native Excel object model. You can, for example, add .NET controls, known as Windows Forms controls, directly to an Excel spreadsheet or Word document and then bind data directly to the controls.

An application-level customization is available to the entire application. VSTO provides an add-in template for Outlook 2003. With Visual Studio 2005 Tools for the 2007 Microsoft Office System (VSTO 2005 SE), you can create add-ins for six applications in the 2007 release of Office and five applications in the 2003 release of Office. You will learn more about VSTO 2005 SE in Chapter 14.

Why Use VSTO Instead of VBA?

Why Use VSTO Instead of VBA?

VSTO provides a professional development environment for developers who want to build applications that target Office. There are many reasons you might want to create solutions using VSTO, as well as some reasons VBA might be the better choice for your solution.

You might choose VBA to create an Office solution if you want to do the following:

• Create application-level customizations for versions of Office older than Office 2003 Professional

• Create application-level customizations for Office applications, such as Microsoft Access, that are not supported in VSTO or VSTO 2005 SE

• Create document-level customizations for Office 2003 (Standard Edition)

• Create application-level customizations for Word and Excel by using global templates

• Override native commands of Word, Excel, and Outlook by creating a macro that has the same name as the command you want to override

• Adhere to organizational requirements that prohibit deploying the .NET Framework to end-user computers

You might choose to use VSTO or VSTO 2005 SE to create an Office solution if you want to do the following:

• Easily add smart tags to your solutions

• Provide smart tags that are available only to a particular document

• Use a richer set of controls both on the document and on the task pane

• Store data in a document for offline use that can easily be updated the next time the document is online

• Create add-ins that have a stable loading and unloading mechanism

• Customize the task pane using only a few lines of code

• Easily customize the Ribbon in Office 2007

• Customize Outlook 2007 form regions

• Access the .NET Framework class libraries

• Use more robust debugging tools

• Gain access to the many tools in Visual Studio's integrated development environment (IDE), such as the Data Sources window and rich IntelliSense features

• Write your solution in managed code using a professional development language such as Visual Basic 2005 or Visual C#

• Use an easier method of maintaining code and updating deployed solutions, making code changes in one location (within a single assembly) rather than within multiple copies of a document or in a global template

• Reduce the possibility of macro viruses by preventing end users from deciding whether code is safe to run

• Gain data binding capabilities for objects on a document within your Office solutions

• Gain access to the events exposed on the extended Office objects that VSTO provides

For discussion of the main language differences between VBA and Visual Basic 2005, see Chapter 4, Moving from VBA to VSTO and Visual Basic 2005. For a description of how to migrate solutions from VBA to VSTO, see Chapter 12, Migrating VBA Solutions to VSTO.

0 0

Post a comment