Office Documents in the Visual Studio Environment Overview
The features in this topic are available only if you have the required applications installed.
For more information, see.
Working with Microsoft Office 2003 documents in Microsoft Visual Studio 2005 Tools for the Microsoft Office System is very similar to working with Windows Forms. When you start a Visual Studio Tools for Office project, the Office document (Microsoft Office Word 2003 document or Microsoft Office Excel 2003 workbook) opens inside of Visual Studio, and the document behaves as a visual designer.
There are two views in the designer: Design view and Code view. Some of the functionality of these two views is the same no matter which Office application is open in the Visual Studio environment. Some functionality depends on whether Word or Excel is currently open.
Design view is the graphical view of the document and application. The Office document opens in the designer. The designer enables you to access the Office menus and toolbars and design the document without having to go outside of the Visual Studio environment. The Word and Excel menus are merged with the Visual Studio menus, but the toolbars are in the designer just above the document. For more information, see.
You can edit and modify a document or workbook using the native functionality of the Office application, for example using Undo, writing Excel formulas, and using the Find feature of Office. You can also use the Visual Studio tool windows and editors to customize the document or workbook using managed code. Keyboard shortcut mapping defaults to the Visual Studio mapping, but you can include Office mappings by changing the setting in the Options dialog on the Tools menu, under the Microsoft Office Keyboard Settings node.
You can drag and drop a control from the Visual Studio Toolbox onto the document design surface, and modify the control properties using the Properties window. Double-clicking the control will open the Code view with an automatically generated event handler. Controls that are not visible in the document appear in the component tray during design time.
Word and Excel have a design mode that enables customizations that cannot be performed during the normal run-time mode. When a document is open in the Visual Studio environment, it is always in design mode. To view the document in run-time mode, you must open the application and the document outside of Visual Studio. You can also build and run the project, which will automatically open the document and application outside of Visual Studio.
The code editor associated with the document in the designer is the same as the code editor you find behind Windows Forms. For more information, see.
Each Excel worksheet has a design view that is a normal worksheet, and the design view of the workbook is a large component tray that fills the designer. The worksheet tabs appear at the bottom of the worksheets, and you can navigate from one to another by clicking the tabs as you would in Excel. There is also a code file associated with each worksheet and with the workbook.
When you write code behind a worksheet or the workbook, your code is local to that object. However, you can access the other objects by using
Globals in your code. For more information, see .
When you double-click a normal worksheet cell, the cell switches to edit mode. When you double-click a cell that contains a host control, the code editor opens and the default event handler is generated. For more information about host controls, see.
There is only one design view for Word documents, which is the document itself. When you double-click on the document surface, your cursor moves to that location as usual in Word. Similarly, when you double-click a word, that word is selected. However, if the word is inside a host control, the code editor opens and the default event handler for the control is generated. For more information about host controls, see.
Word and Excel toolbars appear inside the designer and are fully functional. The set and layout of the toolbars is the same as when you open Word and Excel outside of Visual Studio.
Inside the Visual Studio environment:
You can add and remove toolbars using the View menu or by right-clicking the toolbar in the designer.
You cannot dock Word and Excel toolbars into the Visual Studio set of toolbars.
You cannot customize toolbar layout within a toolbar group by pressing the ALT key, and then selecting the control and moving it.
Toolbar customization such as adding, removing, or moving toolbars lasts only as long as the customized window is open. The customizations are gone the next time the same document, or any other document, is opened. When a document opens, the toolbar settings are identical to the settings of the standalone application.
You cannot move toolbar commands into the menus.
You use Solution Explorer the same way as you would in other types of projects, such as Windows Forms.
Some of the items added to Visual Studio Tools for Office projects include:
References to Office 2003 and the primary interop assemblies. These only appear in Solution Explorer in C# projects; in Visual Basic, they are listed in the project properties.
For Excel, each worksheet and chart appears as a separate item in Solution Explorer.
Some files are hidden. To view these files, click the Show All Files button. For more information, see.
Hidden worksheets appear in Solution Explorer, but not in the designer. For more information, see.
You can add other regular project items such as Windows Forms, code files, and so on. For more information about the Solution Explorer, see.
The Properties window displays properties for the code-behind project items and for the project items in the designer, such as controls and the document itself. Some properties are specific to the application and document, and some properties are the same across all projects.
Data Sources Window
Just as with Windows Forms, you can use the new Data Sources window in your Visual Studio Tools for Office projects to drag and drop a data source onto your document and automatically include a control that is bound to the data source. For more information, see.
When an Office document has focus, invoking the print command from the file menu will bring up the application's print dialog. Using the print command from the application's toolbar in the designer will print the document using the default print options.