Sdílet prostřednictvím


Extensibility in Office Projects

Visual Studio includes a programmable object model that exposes the Visual Basic and Visual C# projects and the project items they contain. This model contains several objects that may be used for automating tasks in the integrated development environment (IDE) and extending project types and project items. The object model is available simply by adding a reference to the VSLangProj.dll assembly to any project. For more information, see Introduction to Project Extensibility.

There are four areas in which you can automate Office projects:

  • Creating projects using the Visual Studio Tools for Office Project Wizard.

  • Executing commands in the Commands collection.

  • Editing project properties.

  • Editing file properties.

Creating Projects Using the Visual Studio Tools for Office Project Wizard

You can automate the Visual Studio Tools for Office Project Wizard to:

  • Create a project, including a new document, using default wizard settings.

  • Create a project, including a new document, with a custom name and location.

  • Create a project for an existing document with a custom path.

For more information, see Walkthrough: Creating a New Office Project Using Visual Studio Project Automation.

Executing Commands in the EnvDTE.Commands Collection

There are two commands in the Commands collection for Microsoft Office Excel. Microsoft Office Word does not expose any commands into the Commands collection. For more information, see Referencing Automation Assemblies and the DTE2 Object.

The two available commands are:

  • Add Excel Worksheet

  • Add Excel Chart

For more information, see How to: Add Worksheets to Workbooks Using Visual Studio Project Automation.

Editing File Properties

Use the Properties collection to get to the properties of the items in a project.

The ProjectItem properties are:

Document property:

  • Namespace for Host Item (C# only)

Document, workbook, and sheet property:

  • Display Name

For more information, see How to: Change Excel Properties Using Visual Studio Project Automation.

Title

Description

Walkthrough: Creating a New Office Project Using Visual Studio Project Automation

Demonstrates how to create a macro that uses the Visual Studio object model to automate the creation of an Office project.

How to: Add Worksheets to Workbooks Using Visual Studio Project Automation

Provides the code to add a new worksheet to an existing Microsoft Office Excel workbook that is open in the Visual Studio designer.

How to: Change Excel Properties Using Visual Studio Project Automation

Provides the code to change an Excel worksheet property to rename the worksheet.

Extending the Visual Studio Environment

Provides links to topics that explain the Visual Studio tools for extending and automating the integrated development environment (IDE).

Introduction to Project Extensibility

Describes how to control Visual Basic and Visual C# projects and solutions using their automation objects.

Designing and Creating Office Solutions

Provides links to information on creating Microsoft Office Word and Excel solutions and the role of assemblies in your solution.