Share via


Overview of Classes and Interfaces in the Office Primary Interop Assemblies

Overview of Classes and Interfaces in the Office Primary Interop Assemblies

If you are migrating to .NET Framework development from traditional application development using Visual Basic for Applications (VBA) and the Component Object Model (COM), you may notice that many interfaces that were previously hidden are now exposed in the Office Primary Interop Assemblies (PIAs).

For example, the Object Browser in the Visual Basic editor for Microsoft Excel shows a single Application class with no other related Application interfaces. In Visual Studio, the Object Browser lists a class named ApplicationClass and two related interfaces (Microsoft.Office.Interop.Excel.Application and _Application) for the Microsoft.Office.Interop.Excel namespace. In addition, there are several interfaces and delegates related to Application events.

Many of these interfaces are required for .NET Framework development, but others should be avoided. This topic provides guidelines for using PIA classes and interfaces.

classidClass Classes

Avoid using members in a classidClass class such as the ApplicationClass class in Microsoft Word. Using these classes has the potential to cause ambiguities with members that share the same name, such as the Microsoft.Office.Interop.Word._Application.Quit(System.Object,System.Object,System.Object) method and Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit event. Instead, use the specific interface where the member is exposed.

For more information, see Understanding Office Primary Interop Assembly Classes and Interfaces.

Classes and Interfaces for Internal Use Only

Avoid directly using any of the following classes and interfaces, which are used internally and are typically not used directly.

Class/Interface Examples

classid Class

ApplicationClass (Word or Excel)

WorksheetClass (Excel)

classid Events x _SinkHelper

ApplicationEvents4_SinkHelper (Word)

WorkbookEvents_SinkHelper (Excel)

_classid

_Application (Word or Excel)

_Worksheet (Excel)

classid Events x

ApplicationEvents4 (Word)

AppEvents (Excel)

I classid Events x

IApplicationEvents4 (Word)

IAppEvents (Excel)

For more information, see Understanding Office Primary Interop Assembly Classes and Interfaces.

Multiple Version Interfaces

The Microsoft Word and Outlook PIAs expose multiple event interfaces for different product versions. Use the interface appropriate to the version.

For example, Application events in Word 97 are associated with the ApplicationEvents_Event interface, while Application events in Word 2003 are associated with the ApplicationEvents4_Event interface.

For more information, see Understanding Office Primary Interop Assembly Events.

Language Differences in Creating Event Handlers

The Visual Basic and C# programming languages have different mechanisms for creating event handlers. In Visual Basic, use the AddHandler statement to create an event handler for an event exposed in a PIA. In C#, use the corresponding event handler delegate. For example, to create an event handler in C# for the Quit event in Microsoft Word 2003, use the ApplicationEvents4_QuitEventHandler delegate type.

For more information, see Understanding Office Primary Interop Assembly Events.

See Also

Concepts

Office Primary Interop Assembly Reference Documentation Conventions
Office Primary Interop Assembly Code Examples