2
votes

I'm looking to create a single ribbon that different apps can access. Essentially I have several VSTO excel add-ins that are built separately and have separate install files. They all have their own ribbon (though I do give the ribbon the same description and name in each project). Is there a way to have them (them being the apps) install on a single ribbon in the excel UI? If a user installs more than one app they end up with two ribbon sections named the exact same thing.

I did find this link from 2008 but couldn't get it to work with 2016 VSTO in Visual Studio 2017.

https://blogs.msdn.microsoft.com/vsto/2008/03/10/share-a-ribbon-customization-between-office-applications-norm-estabrook/

1

1 Answers

1
votes

You can make an interface to your application-level Add-In available to other Add-Ins.

You can expose an object in an VSTO Add-in to the following types of solutions:
 - Visual Basic for Applications (VBA) code in a document that is loaded in the same application process as your VSTO Add-in.
 - Document-level customizations that are loaded in the same application process as your VSTO Add-in.
 - Other VSTO Add-ins created by using the Office project templates in Visual Studio.
 - COM VSTO Add-ins (that is, VSTO Add-ins that implement the IDTExtensibility2 interface directly).
 - Any solution that is running in a different process than your VSTO Add-in (these types of solutions are also named out-of-process clients). These include applications that automate an Office application, such as a Windows Forms or console application, and VSTO Add-ins that are loaded in a different process.

Add markup.

[ComVisible(true)]
public interface IAddInUtilities
{
    void ImportData();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddInUtilities : IAddInUtilities
{
    // This method tries to write a string to cell A1 in the active worksheet.
    public void ImportData()
    {
        Excel.Worksheet activeWorksheet = Globals.ThisAddIn.Application.ActiveSheet as Excel.Worksheet;

        if (activeWorksheet != null)
        {
            Excel.Range range1 = activeWorksheet.get_Range("A1", System.Type.Missing);
            range1.Value2 = "This is my data";
        }
    }
}

Provide it.

private AddInUtilities utilities;

protected override object RequestComAddInAutomationService()
{
    if (utilities == null)
        utilities = new AddInUtilities();

    return utilities;
}

Call it from another add-in.

object addInName = "ExcelImportData";  
Office.COMAddIn addIn = Globals.ThisAddIn.Application.COMAddIns.Item(ref addInName);  
ExcelImportData.IAddInUtilities utilities = (ExcelImportData.IAddInUtilities)addIn.Object;  
utilities.ImportData();