Accessing the API
You can access programmatically the add-in's COM API in one of the following ways:
•from within Excel, by using Visual Basic for Applications (see also https://docs.microsoft.com/en-us/office/vba/library-reference/concepts/getting-started-with-vba-in-office)
•from your custom program, by using the Office Interop API from any .NET language.
The main interface is the IAutomationAPI interface. The following code listing illustrates how to create a new instance of the automation object in VBA.
VBA
Dim automationObject As Object |
Accessing the COM API from a .NET project
To access the COM API from a Visual Studio .NET project, add a reference to the Microsoft Office Object Library (office.dll) and Microsoft.Office.Interop.Excel assemblies:
1.In Solution Explorer, right-click your project's name and then click Add Reference. The Add Reference dialog box appears.
2.On the Assemblies page, select office and Microsoft.Office.Interop.Excel from the component list, and click OK.
If you do not see the assemblies above:
1.Make sure that you have installed Microsoft Office and that you have selected the .NET Programmability Support feature for Excel, for example:
2.Run the Visual Studio setup and make sure that you choose Office/SharePoint development workload (or the Microsoft Office Developer Tools, if applicable).
For more information about accessing Office interop assemblies from .NET projects, see https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/interop/how-to-access-office-onterop-objects.
After adding the assembly references, you can create a new add-in instance as shown below.
C#
// Make sure that your project references the following two assemblies: var app = new Microsoft.Office.Interop.Excel.Application(); |