Redigera

Dela via


Office project templates overview

The Microsoft Office developer tools in Visual Studio include project templates for creating the following types of Office solutions:

  • Document-level customizations

  • VSTO Add-ins

    For a detailed comparison of these types of Office solutions, see Office solutions development overview (VSTO).

    The Office project templates are available in the New Project dialog box, under the Office node of the Visual C# and Visual Basic language nodes. Each template generates a project with the appropriate configuration for the target application, including assembly references and debugging settings.

    Each project provides files and code to get you started on a specific kind of solution. The generated code for each project includes startup and shutdown event handlers. You can add code to these event handlers to initialize your solution when it is loaded and to clean up your solution when it is unloaded. For more information, see Office projects in the Visual Studio environment and Events in Office projects.

Note

The Office development tools are included with certain editions of Visual Studio. For more information, see Configure a computer to develop Office solutions.

Document-level customizations

The Office node in the New Project dialog box provides the following project templates to get you started creating document-level customizations for Word and Excel:

  • Word 2013 and 2016 VSTO Document

  • Word 2013 and 2016 VSTO Template

  • Excel 2013 and 2016 VSTO Workbook

  • Excel 2013 and 2016 VSTO Template

  • Word 2010 VSTO Document

  • Word 2010 VSTO Template

  • Excel 2010 VSTO Workbook

  • Excel 2010 VSTO Template

    The Word Document and Excel Workbook project templates provide code to get you started creating a solution that is based on a specific document or workbook. In these types of solutions, your code runs only when the associated document is open in Word or Excel.

    The Word Template and Excel Template project templates behave identically to the Word Document and Excel Workbook project templates. However, the Word Template and Excel Template project templates makes it easy for users to create new local document or workbook copies of the customized template in your solution. The features in your solution are available from the new document that the user creates from the template.

Note

Word templates that reference managed code extensions cannot be used as global VSTO 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).

For information about getting started with these project types, see the following topics:

VSTO Add-ins

The Office/SharePoint node in the New Project dialog box provides the following project templates to get you started creating VSTO Add-ins.

Document vs. template solutions

When you design a solution around a Word document or Excel workbook, you must decide the best way to make that document available to your users.

Applies to: The information in this topic applies to document-level projects for Excel and Word. For more information, see Features available by Office application and project type.

In some situations, you might want to give a copy of a document to each user. In this case, create your solution by using an Excel or Word document project.

In other situations you might want to make a template available on a server, so that each user can open the template and save a local copy as a document. In this case, create your solution by using an Excel or Word template project.

Comparison

The following table outlines the differences between documents and templates.

Documents Templates
Users can open and modify a document, unless it is set to be read-only. Any saved changes are kept in the original. Users can open a template to create a local copy as a new document. They cannot modify the original unless they are given special permissions.
When opened, the document raises the Open event. When opened, the template raises the New event.

Limitations of global templates and Excel Add-ins (.xla Files)

Documents, workbooks, and templates might not work correctly as global templates or Excel VSTO Add-ins (.xla files).

Word templates

If a Microsoft Office Word template has managed code extensions, the project assembly is not called if the template is attached as a global template or loaded from the startup directory of Word. In addition, the document does not recognize the format of a template that is part of an Office solution.

Excel Add-ins (.xla Files)

There is no Office project for creating an Excel VSTO Add-in (.xla file). It is possible to save a workbook as an .xla file, but it is not a supported operation and is not recommended. If you save a workbook that has managed code extensions as a Microsoft Office Excel Add-In (*.xla) file, you can select it in the Add-Ins dialog box to apply to another workbook. In some cases, your code will run in the target workbook after the VSTO Add-in is applied, but such use of the Office solution is not supported.