This documentation is archived and is not being maintained.

Office Solutions Programming Model

The Microsoft Office object model exposes a variety of objects that you can program against. Normally when you use Automation to program against Microsoft Office applications by using managed code, you write code directly against the primary interop assemblies. In Visual Studio Tools for Office solutions, you also write code directly against host items in your Visual Studio Tools for Office project.

Microsoft Visual Studio 2005 Tools for the Microsoft Office System (VSTO 2005) also extends some of the objects in Microsoft Office Word 2003 and Microsoft Office Excel 2003 by adding events and data binding capabilities and exposing them as controls that you can drop onto a document in the same way you can drop controls onto a Windows Form. These extended controls are called host controls, and they are only available in document-level projects. For more information, see Host Items and Host Controls Overview.

Using Host Items

Host items provide the Startup and Shutdown events, which are entry points for your code in Visual Studio Tools for Office solutions. To initialize your add-in, you can add code to the Startup event handler. To clean up resources used by your add-in, you can add code to the Shutdown event handler. For more information, see Visual Studio Tools for Office Project Events.

Host items also provide entry points into the object model of the host application. In document-level projects that are provided by VSTO 2005, host items derive from classes in the host application's object model, such as Worksheet and Document.

Host items in application-level projects that are provided by Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System (VSTO 2005 SE) do not derive from classes in the host application's object model. Instead, they provide a field that returns an object that represents the current instance of the host application. For more information, see Getting Started Programming Application-Level Add-ins.

Using Host Control Events and Data Binding

Host controls have programmable events. For example, a native Excel Range does not have any events, but you can program against the Change event of a NamedRange control. For more information, see Walkthrough: Programming Against Events of a NamedRange Control.

You can code against these events the same way you use events of controls on Windows Forms. For more information, see Events Overview (Windows Forms).

Host controls also have data binding capability that works in a way that is similar to controls on Windows Forms. Host controls enable you to do simple data binding or complex data binding. For more information, see Binding Data to Controls Overview and Data Binding and Windows Forms.

Programming Against Data in Document-Level Projects

Data in document-level projects can be stored separately from the document in an embedded data island, in a way similar to the way that ASP.NET Web pages store data. By using an embedded data island to store data, you can access the data without starting Word or Excel to instantiate the document, and without using the object model of the application. For more information, see Data in Office Solutions Overview.

Schema-Based Programming

The recommended way to access and manipulate data in Office projects is to create typed datasets to hold the data you are using. With schema-based programming you can define your own object model and program in a more intuitive way, using business-oriented code instead of Office-oriented code. You can concentrate on the solution rather than on the Office object model. For more information about typed datasets, see Datasets in Visual Studio Overview.

Server-Side Programming

Since data is stored in an embedded data island, you can directly access the data that is associated with documents stored on a server without starting the Microsoft Office application. For more information, see Server-Side Access to Data in Documents Overview.

See Also

Show: