AddIn Host Item

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Applies to

The information in this topic applies only to the following project types and versions of Microsoft Office. For more information, see Features Available by Office Application and Project Type.

Project type

  • Application-level projects

Microsoft Office version

  • 2007 Microsoft Office system

  • Microsoft Office 2010

The Microsoft.Office.Tools.AddIn class is the host item for application-level add-ins that you create by using the Office project templates in Visual Studio. A host item is a class in an Office project 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 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 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. The Visual Studio Tools for Office runtime 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 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, the ThisAddIn class derives from OutlookAddIn. You use the ThisAddIn class in Outlook 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 Events in Office Projects.

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 Events in Office Projects.

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.

Use the VstoSmartTags field of the ThisAddIn class. This field is available only in add-in projects for Excel and. 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 Office Solutions.

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

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

NoteNote
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

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 Office Solutions

Getting Started Programming Application-Level Add-Ins

Events in Office Projects

Other Resources

Programming Application-Level Add-Ins