Comparteix a través de


Office projects in the Visual Studio environment

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Microsoft Office projects have a development experience that is similar to other types of projects in Visual Studio, such as Windows Forms projects. When you create or open an Office project, the project items appear in Solution Explorer. For document-level projects, the document (that is, the Word document or Excel workbook) opens in Visual Studio, and the document behaves as a visual designer.

Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects. See Features available by Office application and project type.

Project items in Solution Explorer

In a document-level project, Solution Explorer displays the following default items:

  • Nodes for the document, workbook, and sheets that are customized by the project. These nodes serve as containers for the code files that are associated with the document, workbook, and sheets.

  • Code files that are associated with the document, workbook, and sheets that are customized by the project. In Word projects, code files are associated with the Word document or template. In Excel projects, code files are associated with the Excel workbook or template, and with each worksheet and chart sheet in the workbook or template.

  • Hidden project files that you are not intended to edit directly. For more information, see Hidden project files.

    In a VSTO Add-in project, Solution Explorer displays the following default items:

  • The application node. This node has the same name as the host application, such as Word, Excel, or Outlook. The application node contains the ThisAddIn code file. It also provides the Namespace for Host Item property. For more information about this property, see Properties in Office projects.

  • The ThisAddIn code file. This file contains the generated ThisAddIn class for your VSTO Add-in. For more information about this class, see Program VSTO Add-Ins.

  • Hidden project files that you are not intended to edit directly. For more information, see Hidden project files.

Temporary Certificates

Office projects also include a temporary certificate named Project Name_TemporaryKey.pfx. This certificate is used to sign the application and deployment manifests for the project during development. For more information, see Grant trust to Office solutions and Secure Office solutions.

Hidden project files

Several project files are hidden by default. These files are generated by Visual Studio, and they differ by project type. To display the hidden files, click Show All Files in Solution Explorer.

Do not modify the hidden project files. Changing these files directly is not supported, and might corrupt your project. The hidden project files are regenerated whenever certain changes occur in the document. If you make manual changes to a hidden project file, those changes are lost when the file is regenerated.

Document designer in document-level projects

Document-level projects for Excel and Word provide a designer that hosts the document that is associated with your project in Visual Studio. The designer enables you to modify the document without having to go outside the Visual Studio environment.

To open a document in the designer, double-click the code file in Solution Explorer that is associated with the document. For example, to open the worksheet Sheet1 in the designer in an Excel project, double-click the Sheet1 code file.

When you modify the document in the designer, you can leverage the native functionality of the Office application. For example, you can type text in the document or a worksheet, or you can use the Ribbon to perform tasks like adding a table or chart. By default, keyboard shortcut mapping defaults to the Visual Studio mapping. To use Office keyboard shortcut mappings instead, change the settings under the Microsoft Office Keyboard Settings node in the Options dialog box on the Tools menu.

Controls on Documents

You can drag host controls and Windows Forms controls from the Visual Studio Toolbox onto the document design surface. Host controls are specialized versions of Office objects, such as Word content controls and Excel ranges, that can be used in Office projects created by using Visual Studio. Host controls have additional features that are not available in the corresponding Office objects, such as data binding and additional events.

For more information, see Host items and host controls overview and Windows forms controls on Office documents overview.

Excel worksheets and workbooks in the Designer

When you open a worksheet in the designer, you can modify the worksheet in the same way that you can when it is open directly in Excel. If you double-click a worksheet cell, the cell changes to edit mode. If you double-click a cell that contains a host control, the Code Editor opens and Visual Studio generates the default event handler for the control. To navigate to other worksheets, you can click the worksheet tabs at the bottom of the designer.

When you open the workbook in the designer, there is no design surface. The design view for the workbook is a large component tray that fills the designer.

The workbook and each sheet in the workbook has an associated code file. Each code file contains a generated host item class that represents the workbook or sheet. For more information, see Automate Excel by using extended objects.

Word documents in the designer

When you open the document in the designer, you can modify the document in the same way that you can when it is open directly in Word. If you double-click a word in the document, that word is selected. However, if the word is inside a host control, the code editor opens and Visual Studio generates the default event handler for the control.

The document has an associated code file. The code file contains a generated host item class that represents the document. For more information, see Document host item.

Design mode vs. runtime mode

When a document is open in the Visual Studio environment, it is always in design mode. Some tasks, such as dragging a host control to the document surface, can be performed only design mode.

To view the document in runtime mode, you must open the application and the document outside Visual Studio. You can also build and run the project, which will automatically open the document and application outside Visual Studio.

Code Editor

The Code Editor enables you to view and modify the visible code files in your solution. These files contain the code that defines the behavior of your solution.

For more information about the Code Editor, see Write code in the code and text editor. For more information about how to write code in Office projects, see Write code in Office solutions.

Properties window

The Properties window displays properties for project items that are selected in Solution Explorer, and for UI elements that are selected in the designer, such as controls or the document in a document-level project. Some properties are specific to the application and document, and some properties are the same across all projects.

Data Sources window

You can use the Data Sources window in document-level Office projects to drag a data source onto your document and create a control that is bound to the data source. For more information, see Bind controls to data in Visual Studio.

See also