StephenDonaldHuffPhD
StephenDonaldHuffPhD

Reputation: 958

How to connect a ribbon button to a function defined in an Excel add-in?

I'm using MSVS 2013 to create a C# MS Excel Add-In. In previous add-in paradigms, the ribbon class designer directly connected a ribbon button click event to function in the Add-In application class - now the ribbon functions are defined in the ribbon class, itself. What is the best way to access a function defined in the ThisAddIn class from the separate ribbon control class?

Upvotes: 2

Views: 657

Answers (1)

StephenDonaldHuffPhD
StephenDonaldHuffPhD

Reputation: 958

This is a simple method for doing this:

    private void butRefreshSelectedWorksheets_Click(object sender, RibbonControlEventArgs e)
    {
        try
        {
            Globals.ThisAddIn.RefreshWorksheetListings();
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("Error [butRefreshSelectedWorksheets_Click]: " + ex);
        }
    }

Use the Globals.ThisAddIn.... syntax to access app functions from within the ribbon.

Upvotes: 1

Related Questions