AddIn Host Item

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Application-level projects

Microsoft Office version

  • 2007 Microsoft Office system

  • Microsoft Office 2003

For more information, see Features Available by Application and Project Type.

The Microsoft.Office.Tools.AddIn class is the host item for application-level add-ins that you create by using Visual Studio Tools for Office. A host item is a class in a Visual Studio Tools for Office solution that provides the entry point for your code. 

Understanding the AddIn and ThisAddIn Classes

The AddIn class provides core functionality that is shared by all Visual Studio Tools for Office add-ins. However, you should not explicitly instantiate this class or use it directly in your code.

Instead, use the ThisAddIn class. Visual Studio Tools for Office generates this class in your add-in project to serve as the communication link between the Microsoft Office application and your add-in code. The ThisAddIn class derives from AddIn. Visual Studio Tools for Office automatically instantiates this class for you when a Microsoft Office application loads your add-in.

The ThisAddIn class provides a location in which you can start writing code in your project. You can also use ThisAddIn to perform tasks such as accessing the object model of the host application. For more information, see Programming Application-Level Add-Ins.

Using AddIn and ThisAddIn in Outlook 2007 Add-in Projects

Add-in projects for Microsoft Office Outlook 2007 use a different host item, Microsoft.Office.Tools.Outlook.OutlookAddIn. This class derives from AddIn, and adds some additional functionality to support form regions. For more information about form regions, see Creating Outlook Form Regions.

In add-in projects for Outlook 2007, the ThisAddIn class derives from OutlookAddIn. You use the ThisAddIn class in Outlook 2007 add-ins just like you use this class in add-ins for other Microsoft Office applications.

Members to Use for Various Tasks

The following table describes common tasks and shows which members of the ThisAddIn class you can use to perform the tasks.

Task

Member to use

Run code to initialize the add-in when the add-in is loaded.

Add code to the ThisAddIn_Startup method. This is the default event handler for the Startup event. For more information, see Visual Studio Tools for Office Project Events.

Run code to clean up resources used by the add-in before the add-in is unloaded.

Add code to the ThisAddIn_Shutdown method. This is the default event handler for the Shutdown event. For more information, see Visual Studio Tools for Office Project Events.

Automate the host application by accessing the object model.

Use the Application field of the ThisAddIn class. This returns an instance of the Application class of the application that your add-in works with. For more information, see Programming Application-Level Add-Ins.

Create a smart tag that can be recognized in any open Word document or Excel workbook. This feature is new in Visual Studio 2008 Service Pack 1 (SP1).

Use the VstoSmartTags field of the ThisAddIn class. This field is available only in add-in projects for Excel 2007 and Word 2007 that you create after you install SP1. For more information, see Smart Tags Overview.

Expose objects in your add-in to other Microsoft Office solutions.

Override the RequestComAddInAutomationService method. For more information, see Calling Code in Application-Level Add-ins from Other Solutions.

Customize a feature in the 2007 Microsoft Office system by implementing an extensibility interface.

Override the RequestService method to return an instance of a class that implements the interface. For more information, see Customizing UI Features By Using Extensibility Interfaces.

Note

To customize the Ribbon UI, you can also override the CreateRibbonExtensibilityObject method.

See Also

Tasks

Walkthrough: Calling Code in an Application-Level Add-in from VBA

Concepts

Programming Application-Level Add-Ins

Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time

Customizing UI Features By Using Extensibility Interfaces

Calling Code in Application-Level Add-ins from Other Solutions

Getting Started Programming Application-Level Add-Ins

Visual Studio Tools for Office Project Events

Change History

Date

History

Reason

July 2008

Added information about adding smart tags to documents by using application-level add-ins.

SP1 feature change.