Bagikan melalui


Getting Started Programming Document-Level Customizations for Word

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

Microsoft Office version

  • Word 2003

  • Word 2007

For more information, see Features Available by Application and Project Type.

If you are just getting started creating document-level customizations for Microsoft Office Word by using Visual Studio Tools for Office, here is what you need to know.

The Single Document Application Model

Each Word customization you create is based around a single document. To start using the customization, the end user opens the document or creates the document from a Word template. Events in the document, for example moving the cursor into specific areas or clicking buttons and menu items, can call event-handling methods in the assembly. For more information, see Architecture of Document-Level Customizations.

Programming Word Documents by Using Host Items Host Controls

Host items and host controls are classes that provide the programming model for document-level customizations.

Host items provide an entry point for your code, and they can also act as container for controls such as host controls and Windows Forms controls. Word customizations use the Microsoft.Office.Tools.Word.Document host item. This host item has a designer that is the visual representation of the Word document in your project, like a Windows Forms designer. In your project, this host item is represented by the ThisDocument class, which derives from the Microsoft.Office.Tools.Word.Document host item. For more information, see Host Items and Host Controls Overview and Document Host Item.

Host controls are based on native Word objects, such as content controls, bookmarks, and XML nodes. Host controls provide similar functionality to the native Word objects, but they also have new events, designer support, and data-binding capability. They appear as first-class objects in the Visual Studio Tools for Office programming model and in IntelliSense, which makes it easier to refer to specific objects directly in your code without having to navigate the Word object model. For more information, see Host Items and Host Controls Overview and Word Host Controls.

There are different host controls available in document-level projects for Word 2003 and Word 2007. In both sets of projects, you can use the Bookmark and XMLNode controls. In Word 2007 projects, you can also use content controls. For more information, see Content Controls, Bookmark Control, and XMLNode Control.

Binding Controls to Data

The content controls and the Bookmark control are in the list of controls that you can drag from the Data Sources window. Adding content controls and bookmarks in this way automatically binds them to the data source that you set up by using the window. Without writing any code, you can display data from databases, Web services, and objects in your document. For more information, see Binding Data to Controls in Office Solutions.

Customizing the User Interface of Word

Most Microsoft Office solutions modify the user interface (UI) of the Office application to provide some way for users to interact with the solution. There are many ways in which you can modify the UI of Word by using a document-level customization. For example, you can add controls to the Ribbon, you can display an actions pane, and you can create smart tags that respond to specific strings that users type in the document. For more information, see Office UI Customization.

Next Steps

For a list of topics that walk you through some of the common tasks in Word automation, see Common Tasks in Office Programming.

See Also

Tasks

Walkthrough: Creating Your First Document-Level Customization For Word

Concepts

Walkthroughs Using Word

Word Solutions

Word Object Model Overview

Getting Started Writing Code

Getting Started Programming Document-Level Customizations for Excel

Other Resources

Getting Started (Visual Studio Tools for Office)