Share via


Office Projects in the Visual Studio Environment

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 application-level projects for Microsoft Office 2010 and the 2007 Microsoft Office system. For more information, 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.

  • Worksheets that have been hidden from view in Excel. The code files for these worksheets appear in Solution Explorer, even though the corresponding worksheets do not appear in the designer. For more information, see Hidden Worksheets.

In an application-level 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 add-in. For more information about this class, see Programming Application-Level 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 Granting Trust to Office Solutions and Securing 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 Workbook Host Item, Worksheet Host Item and ChartSheet Host Item.

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. Run Time 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 run-time 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 Code and Text Editor. For more information about how to write code in Office projects, see Writing 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 Binding Controls to Data in Visual Studio.

See Also

Tasks

How to: Create Office Projects in Visual Studio

Concepts

Using Solution Explorer

Properties in Office Projects

Hidden Worksheets

Other Resources

Designing and Creating Office Solutions

Office Project Templates Overview