Word Document Project Template

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 2007

  • Word 2003

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

The Word Document project template in Visual Basic and Visual C# provides the groundwork for solutions that are based on new or existing Microsoft Office Word documents. There are different project templates for Word 2003 documents and Word 2007 documents. The project templates automatically add the necessary assembly references, files, and generated code to use as a starting point for your solution.

Note

By default, some of the files and references in the following list are hidden. To see them, click Show All Files on the Solution Explorer toolbar. Additionally, there are some files and references not in the following list that are common to many Visual Studio project templates.

Files

Visual Studio Tools for Office generates the following visible files in Word 2003 and Word 2007 document projects:

  • Document Name.doc - Represents the Word document in the project. Contains the document design surface and the code file.

  • ThisDocument (.vb file for Visual Basic or .cs file for Visual C#) - A document that provides the design surface and the code file. For more information, see Document Host Item.

Note

You cannot add additional classes to the code file behind a document. You must add new files to your project to contain any classes you want to write.

Visual Studio Tools for Office also generates the following additional file when you build a Word 2007 workbook project:

Hidden Files

Visual Studio Tools for Office generates several hidden files. Do not modify these files manually; they are regenerated when changes are made to the project and they do not retain manual modifications.

Visual Studio Tools for Office generates the following hidden files:

  • ThisDocument.Designer.xml - A read-only declarative representation of the programmable objects in the document.

  • ThisDocument.Designer (.vb file or .cs file) - A read-only code file that provides helper implementations for objects in the document, including code to instantiate objects correctly.

  • Document Name.Designer.xml - A read-only declarative representation of programmable objects such as custom controls that are not part of Visual Studio Tools for Office by default. This file is generated when you add a custom control to the document.

  • Document Name.Designer (.vb file or .cs file) - A read-only code file that provides helper implementations for custom controls. This file is generated when you add a custom control to the document.

Template Code

The following event handlers are included in the project template code files. For more information, see Visual Studio Tools for Office Project Events.

ThisDocument_Startup

ThisDocument_Startup handles the Document.Startup event. This event is raised after the solution is running and all the initialization code in the assembly has run. Use this event handler to run code that initializes your solution.

ThisDocument_Shutdown

ThisDocument_Shutdown handles the Document.Shutdown event. This event is raised when the application domain that your code is loaded in is about to unload.

References

Visual Studio Tools for Office automatically creates a set of assembly references in Word document projects. These references include the following assemblies:

  • Assemblies in the Visual Studio Tools for Office¬†runtime. For more information about these assemblies, see Visual Studio Tools for Office Runtime Overview.

  • Primary interop assemblies for shared Microsoft Office components and for Word. For more information, see Office Primary Interop Assemblies.

  • .NET Framework assemblies that are used when you develop Visual Studio Tools for Office solutions.

See Also

Tasks

How to: Create Visual Studio Tools for Office Projects

Concepts

Assemblies in Office Solutions Overview

Word Object Model Overview

Other Resources

Managing Solutions, Projects, and Files

Office Project Templates