1
votes

I'm developing an Outlook Add In. It's pretty much done already, but there's one thing that I can't seem to put my finger on. In my (Outlook Add In) project I added a new item (Ribbon (Visual Designer)) which I called EmailTransferRibbon. This Ribbon is being displayed in Outlook. I want to be able to start my Outlook Add In when I click on this Ribbon button.

This is what my Ribbon looks like:

public partial class EmailTransferRibbon
{
    private void EmailTransferRibbon_Load(object sender, RibbonUIEventArgs e)
    {   
    }

    private void btnEmailTransfer_Click(object sender, RibbonControlEventArgs e)
    {
    }
}

And this is the add in where I want the Ribbon button to navigate to:

public partial class ThisAddIn
{
    EmailTransferForm emailTransferForm = new EmailTransferForm();

    public void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        InboxFolderItemAdded();
        Button btnRefresh = emailTransferForm.Controls.Find("btnRefresh", true).FirstOrDefault() as Button;
        btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);

    }
}

I tried to do something like this, but this is a problem because RibbonControlEventArgs is not the same as System EventArgs:

var addIn = Globals.ThisAddIn;
addIn.ThisAddIn_Startup(sender, e);

Can someone tell me how to start the my add in by pressing the Ribbon button? thanks!

1

1 Answers

0
votes

You can set your add-in to "load on demand", which can create your Ribbon UI and effectively cache your add-in until you want to load it completely:

Demand-Loading VSTO Add-ins - Andrew Whitechapel - Site Home - MSDN Blogs http://blogs.msdn.com/b/andreww/archive/2008/07/14/demand-loading-vsto-add-ins.aspx

If you don't want your add-in to load at all until you click a button, then that button will need to call VBA code to load your add-in, or the button needs to be powered by another add-in that will load your add-in. In either case, you need to use the Office Object Model to access the COMAddins collection from Outlook.Application.COMAddINs and get the specific COMAddIn object for your add-in (matching on the ProgID value) and set Connect = True to load your add-in.