Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

AddIn.RequestService Method

Returns an object that extends a feature in the 2007 Microsoft Office system.

Namespace: Microsoft.Office.Tools
Assembly: Microsoft.Office.Tools.Common (in microsoft.office.tools.common.dll)

protected virtual Object RequestService (
	Guid serviceGuid
)

Parameters

serviceGuid

A Guid that identifies an extensibility interface that is supported by applications in the 2007 Microsoft Office system.

Return Value

An object that implements the extensibility interface that is identified by serviceGuid.

Override this method in an application-level add-in to customize the Ribbon user interface (UI) or to create an Outlook form region. When you override this method, check the value of the serviceGuid parameter to determine which extensibility interface is being requested, and then return an object that implements the interface.

To customize the Ribbon UI, your implementation of the RequestService method must return an object that implements the Microsoft.Office.Core.IRibbonExtensibility interface. When you add a new Ribbon item to your add-in project, Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System (VSTO 2005 SE) overrides this method for you. For more information, see Ribbon Extensibility Overview.

To create an Outlook form region, your implementation of the RequestService method must return an object that implements the Microsoft.Office.Interop.Outlook.FormRegionStartup interface. VSTO 2005 SE does not generate an implementation of RequestService for you. For more information, see Outlook Form Regions Overview.

When your add-in is loaded, the Visual Studio Tools for Office runtime calls RequestService one time for each supported interface and sends the return value to the Microsoft Office application that is loading your add-in.

The following code example demonstrates how to override the RequestService method in an add-in for Microsoft Office Outlook 2007 that customizes the Ribbon UI and creates an Outlook form region. This code example checks to see whether the Microsoft.Office.Core.IRibbonExtensibility or Microsoft.Office.Interop.Outlook.FormRegionStartup interfaces are being requested, and it returns instances of classes that implement these interfaces. This example assumes that your project contains a class named MyRibbon that implements the Microsoft.Office.Core.IRibbonExtensibility interface, and a class named FormRegionHookup that implements the Microsoft.Office.Interop.Outlook.FormRegionStartup interface. For more information about how to implement these interfaces in add-in projects, see Ribbon Extensibility Overview and Outlook Form Regions Overview.

public partial class ThisAddIn
{
    private MyRibbon ribbon;
    private FormRegionHookup formRegionHookup1;

    protected override object RequestService(Guid serviceGuid)
    {
        if (serviceGuid == typeof(Office.IRibbonExtensibility).GUID)
        {
            if (ribbon == null)
                ribbon = new MyRibbon();
            return ribbon;
        }

        if (serviceGuid == typeof(Microsoft.Office.Interop.Outlook.FormRegionStartup).GUID)
        {
            if (formRegionHookup1 == null)
                formRegionHookup1 = new FormRegionHookup();
            return formRegionHookup1;
        }

        return base.RequestService(serviceGuid);
    }
}

Show:
© 2015 Microsoft