Dela via


Getting Started Writing Code

The techniques for writing code are basically the same as for other Visual Studio projects, but the paradigms are slightly different for document-level customizations and application-level add-ins.

Document-Level Customizations

Microsoft Office Word and Microsoft Office Excel document-level customizations have a code file associated with each Word document, and with each Excel workbook and worksheet. The model is the same as Windows Forms and Web Forms; there is a design view for working with the user interface, and there is a code view where you write your code.

Application-Level Add-Ins

You can write application-level add-ins for Microsoft Office Excel, Microsoft Office InfoPath, Microsoft Office Outlook, Microsoft Office PowerPoint, Microsoft Office Visio, and Microsoft Office Word. In these solutions, there is a code file associated with the application. These solutions provide a Code view where you write your code; there is no design view for the application. However, there are separate designers for some features, such as the Ribbon and custom task panes.

Note

You cannot add additional classes to the code file behind a document, workbook, or worksheet. You must add new files to your project to contain any classes you want to write.

Opening the Code View

You can get to the Code view in multiple ways:

  • Click the View Code button on the Solution Explorer toolbar. The insertion point appears at the top of the window.

  • Click the View Code menu item on the Visual Studio View menu when either a document or corresponding code project item is selected in Solution Explorer. The insertion point appears at the top of the window.

  • Click the View Code item on a document's context menu. The insertion point appears at the top of the window.

  • Click the View Code item on the context menu of a control, including host controls. The insertion point appears at the top of the window. For more information about host controls, see Host Items and Host Controls Overview.

  • Click View Code on the project item context menu in Solution Explorer. The insertion point appears at the top of the window.

  • Double-click a control in the visual designer. The insertion point appears inside the default control event handler. The event handler is generated if it does not exist already.

Using Code to Customize Office

Some aspects of Visual Studio Tools for Office projects are different from other types of projects. To learn more about supported programming languages, understanding optional parameters, global access to objects, and collaborative development, see Writing Code in Office Solutions.

When you write code for application-level add-ins, you can customize UI features, call code from other applications, and write code directly against the ThisAddIn class in your project. For more information, see Programming Application-Level Add-Ins.

For document-level customizations, you can add controls to Office documents, combine VBA into your Visual Studio Tools for Office project, and manage documents on a server. For more information, see Programming Document-Level Customizations.

You can programmatically customize the UI of a Microsoft Office application with the Ribbon, actions panes, custom task panes, and smart tags. For more information, see Office UI Customization.

You can use the data processing tools of Visual Studio Tools for Office to connect, bind, and access data in Office documents. XML schemas and XML parts can also be used to add and organize data in documents. For more information, see Data in Office Solutions.

By using project extensibility, you can automate tasks and extend project types and items. For more information, see Project Extensibility in Visual Studio Tools for Office.

Adding Office Descriptions to IntelliSense

Visual Studio IntelliSense does not include descriptions of objects and parameters for many Microsoft Office objects. Typically, text that describes an object or parameter appears in the Quick Info and Parameter Info features, along with the syntax. However, for many objects in the Office object model, this text is not available by default.

You can install files that provide these descriptions for some applications in Office 2003. Visual Studio Tools for Office provides these files for download from the Web. For more information, see the download Web page at Microsoft IntelliSense XML Files for Microsoft Visual Studio Tools for the Microsoft Office System Solution Developers.

See Also

Concepts

Creating Office Solutions in Visual Studio

Reference

Quick Info

Parameter Info

Other Resources

Getting Started (Visual Studio Tools for Office)

Samples and Walkthroughs (Office Development)

Data in Office Solutions

Architecture of Visual Studio Tools for Office Solutions