Book Image

VSTO 3.0 for Office 2007 Programming

By : Vivek Thangaswamy
Book Image

VSTO 3.0 for Office 2007 Programming

By: Vivek Thangaswamy

Overview of this book

With the arrival of Visual Studio Tools for Office 3.0 (VSTO), developers can now program Microsoft Office from the .NET framework. There are huge books in the market that give loads of unnecessary information but are of no real help to brand-new Office developers. Wouldn't it be great to have a precise book that simply covers the basics and introduces programming Office 2007 with VSTO using the latest version of Visual Studio? This is that book. VSTO 3.0 for Office 2007 Programming shows you how to write Office 2007 applications with Visual Studio Tools for Office 3.0. Learn how to automate tasks in InfoPath, Word, Excel, Outlook, PowerPoint, Visio, and Project 2007 with greater programming power and flexibility than was available from the VBA language. With this book and the mastery of VSTO you will learn, Office will no longer be an application to you; it will be a platform for developing custom applications.VSTO 3 is the most recent version of VSTO, making use of Visual Studio 2008, and working with Office 2007. This book shows how VSTO puts Office automation into the hands of developers, allowing them to use the power of the .NET framework to automate Office applications thus increasing the speed of the applications, their security, and the opportunity to use other parts of the .NET Framework such as its data handling capabilities. This book builds a solid programming foundation in VSTO for brand-new Office developers. You will leave behind the world of VBA programming and take your first steps into the powerful and exciting world of using C# to create Office 2007 applications. Packed with examples and covering all the main Office applications, this book will have you creating fully featured Office extensions before you know it.
Table of Contents (11 chapters)
VSTO 3.0 for Office 2007 Programming
Credits
About the Author
About the Reviewers
Preface

Chapter 1. Visual Studio Tools for Office (VSTO)

VSTO is a framework for the development of solutions for Microsoft Office tools. By using VSTO and what is known as managed code, developers can build Office solutions. Before we begin the chapter, let us see an overview of what we are going to cover in this chapter. This book is for Office Developers using Visual Studio Tools for Office. This chapter will make you comfortable with Visual Studio Tools for Office 3.0. We will be covering:

  • What is Microsoft VSTO?

  • Why do we need VSTO 3.0?

  • New features added in VSTO 3.0 as compared with the older version

  • The architecture of VSTO and the tools' approaches

  • Infrastructural setup—system requirements, installation, and so on

  • How VSTO is integrated with Visual Studio 2008, and its integrated design and debugging features

  • New features in the next version of VSTO, and how VSTO can be further improved

VSTO helps you to build document-level solutions, where a solution is specific to the document for which it is deployed. You can build application-level solutions by using the application-level add-in for your solution development. The application-level add-in is accessible to all of the documents processed through that particular application.

What is Microsoft VSTO?

VSTO is a platform for Microsoft Office solution development, built on top of .NET framework. The latest release is version 3.0. Starting with VSTO 3.0, developers have integrated Office clients into the Visual Studio designer and the .NET layers on top of the native object models.

The image above represents how VSTO has been integrated with the Visual Studio 2008 environment. Now, the term "Office solutions" appears a lot. You may have questions like—"What exactly, is an Office solution anyway? What kind of Office solutions can be developed using VSTO?". Let's answer these questions.

An Office solution is a solution developed for Microsoft Office applications, including Word, Excel, InfoPath, Access, or PowerPoint. With the help of VSTO, developers can build Office solutions using what is known as managed code.

Managed code is program code that executes under the supervision of a .NET Framework Common Language Runtime. Programs in any programming language can be compiled using either managed or unmanaged code. Code that is built on the .NET framework is meant to be managed code. Managed code brings easy deployment to your VSTO solution, as compared to VBA(Visual Basic for Applications). VBA is a programming combination of Visual Basic associated with an integrated development environment for Microsoft Office applications.

Unlike VSTO, VBA doesn't support programming languages. VSTO gives you the full support of a programming language to build Microsoft Office solutions. VSTO helps you to build a secure and safe solution for your Office application. All of the VBA scripts will be stored inside the document for which you are programming, while VSTO brings you the new concept called document-level solutions and application-level solutions.

Using VSTO, Office developers can build solutions such as Add-Ins; Add-Ins are additional program components that can be added to Office applications by using VSTO. For example, Microsoft offers a few free add-ins for Office 2007 licensed users, such as the 2007 Microsoft Office add-in Microsoft Save as PDF or XPS—this add-in facilitates the saving of a document in PDF or XPS format. You can also customize existing Office application features, and you can program against existing options available in the Office application. Let's say you need to save or export all of the content from Microsoft Office Word 2007 to Microsoft Office Excel 2007 on the click event of a button placed on the toolbar, or during some action.You can create an add-in for this kind of activity using VSTO. This is one scenario where you can use a VSTO add-in for your Office solution development.

Before VSTO, Office developers had to use VBA, VB6, or C++ to create so called shared COM Add-Ins. All Add-Ins share the same address space, and if one fails, the host application or all other Add-Ins crash. Unlike VSTO, VBA code is written directly in the Office application's IDE and is compiled at run-time. All VBA scripts are stored inside the document for which you were programming. In VSTO, this is termed a document-level solution, where the solution is specific to the document for which it is deployed. Similarly, in VSTO, document level add-ins are delivered within a specific document. For example, let's say that you include functions in a specific Microsoft Office Word document—the functions are available only when you open that particular Word document. Document level add-ins are relevant only to Word and Excel. Document-level customizations are the VSTO version of VBA macros in Word or Excel.

VSTO introduces a new concept called application-level solutions. With an application-level solution, the solution is accessible for all documents processed through that particular application. You can build application-level solutions by using the application-level add-in for your solution development.

VSTO gives you two fully-supported programming languages in which to build Microsoft Office solutions that will run in all Microsoft Office applications—C#, VB.NET, or XML. As a VSTO programmer, you will need to have a basic knowledge of C# to program Office applications using C#. In this book, we will assume that you have a basic knowledge of C# concepts such as classes, namespaces, and methods. In addition, you should know the basics of XML.

Note

The following MSDN reference link will help you learn about .NET and C#: http://msdn.microsoft.com/en-us/vcsharp/aa336804.aspx

In most of the Office 2007 applications, Microsoft has used XML(Extensible Markup Language) as the standard format for data and UI processing. For example, InfoPath forms save data in XML format. C# brings you great programming support for XML and Office applications. Office already has built-in support for an XML-based customization model, of which VSTO takes full advantage. Using C# classes and simple XML, VSTO simplifies the connection between .NET, and the server and Office systems.

  • VSTO leverages two powerful technologies that you may be familiar with—C# and XML. C# is one of the most powerful programming languages supported by Microsoft .NET frameworks.

  • VSTO gives full flexibility to programs using C# and VB.NET programming language for Office 2007 applications.

  • You, as a VSTO programmer, need to have a basic knowledge of C#, in order to program Office applications using C#.

So, for instance, instead of having a Word macro that you need to run in order to create the document you want, you could simply transfer the information to a Word template and have Office create the document for you! VSTO thus provides data-caching capabilities.