Share via


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

Word templates that reference managed code extensions cannot be used as global add-ins. The assembly is not called if the template is loaded from the Startup directory of Word. For more information, see Limitations of Global Templates and Excel Add-ins (.xla Files).

If you open a template to edit it outside of Visual Studio after the solution has been compiled, the template will run the code just as if you had created a new document from the template. Depending on the code, this could alter the template while it opens, before you begin to edit. To prevent the code from running, hold down the SHIFT key while you open the template.

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 template projects:

  • Document Name.dot - Represents the Word template in a 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, workbook, or worksheet. 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 template 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 template projects. These references include the following assemblies:

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