Managed Code and Office Programming with Visual Studio

The key technology that makes creating an integrated Microsoft Office solution possible is Automation, which is part of the Component Object Model (COM) technology. Automation enables you to use code to create and control software objects exposed by any application, DLL, or ActiveX control that supports the appropriate programmatic interfaces.

Microsoft Office Automation Using Managed Code

Microsoft Office applications expose much of their functionality to Automation. However, you cannot use managed code (such as Visual Basic or C#) directly to automate COM-based technology, such as Microsoft Office applications. To work with unmanaged COM objects using managed code in Visual Studio, you must use an interop assembly.

Any number of interop assemblies may exist that describe a given COM type, and Visual Studio even generates one for you that has basic functionality. However, only one interop assembly is labeled the primary interop assembly (PIA), which contains the official description of the COM types as defined by the publisher of the type library. The primary interop assembly may contain certain customizations that make the types easier to use from managed code. It is best to use a primary interop assembly if one is available, rather than relying on an interop assembly from another source.

Every Microsoft Office application has a primary interop assembly. When you create a Visual Studio Tools for Office project for a Microsoft Office application, a reference to the appropriate primary interop assembly is automatically added to the project. To automate the features of other Microsoft Office applications from the project, you must add a reference to the appropriate primary interop assembly manually. For more information, see How to: Target Office Applications Through Primary Interop Assemblies.

Visual Studio Tools for Office includes templates for two main types of projects that automate Microsoft Office applications: document-level customizations and application-level add-ins. For more information, see Office Solutions Development Overview.

See Also

Tasks

How to: Target Office Applications Through Primary Interop Assemblies

How to: Create Visual Studio Tools for Office Projects

Concepts

Developing Office Solutions

Programming with Visual Basic vs. C# in Office Solutions

Reference

Office Primary Interop Assemblies