
Exposing Objects to Other Office Solutions
To expose an object to other add-ins, override the RequestComAddInAutomationService method in the ThisAddIn class. Return the object that you want to expose to other Office solutions.
When your add-in is loaded, the Visual Studio Tools for Office runtime calls the RequestComAddInAutomationService method. The runtime assigns the returned object to the Object property of a COMAddIn object that represents your add-in. This COMAddIn object is available to other Office solutions.
Requirements of the Returned Object
Example
The following code example demonstrates how to override RequestComAddInAutomationService. This example assumes that you have defined a class named AddInUtilities that you want to expose to other Office solutions, and the AddInUtilities class meets the requirements specified above. To see this code in the context of a larger walkthrough, see Walkthrough: Calling Code in an Application-Level Add-in from VBA.
Private utilities As AddInUtilities
Protected Overrides Function RequestComAddInAutomationService() As Object
If utilities Is Nothing Then
utilities = New AddInUtilities()
End If
Return utilities
End Function
private AddInUtilities utilities;
protected override object RequestComAddInAutomationService()
{
if (utilities == null)
utilities = new AddInUtilities();
return utilities;
}