Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook Add-in, RibbonType Microsoft.Outlook.Explorer and Microsoft.Outlook.Mail.Read

I have an Outlook 2010 Add-in coded in .NET 4.0/VS.NET 2010, C#. The Add-in extends the Ribbon => it adds a RibbonTab with 4 RibbonButtons to (RibbonType Property is set to) Microsoft.Outlook.Explorer and Microsoft.Outlook.Mail.Read.

Now, if the user clicks on one of the RibbonButtons, how can i determine if the user clicked on the button which is added to the Microsoft.Outlook.Explorer OR Microsoft.Outlook.Mail.Read?

like image 984
Christian Casutt Avatar asked Apr 18 '13 13:04

Christian Casutt


1 Answers

The proposal from SilverNinja pointed me in a direction .. finally my code is:

                // get active Window
            object activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
            if (activeWindow is Microsoft.Office.Interop.Outlook.Explorer)
            {
                // its an explorer window
                Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
                Outlook.Selection selection = explorer.Selection;
                for (int i = 0; i < selection.Count; i++)
                {
                    if (selection[i + 1] is Outlook.MailItem)
                    {
                        Outlook.MailItem mailItem = selection[i + 1] as Outlook.MailItem;
                        CreateFormOrForm(mailItem);
                    }
                    else
                    {
                        Logging.Logging.Log.Debug("One or more of the selected items are not of type mail message..!");
                        System.Windows.Forms.MessageBox.Show("One or more of the selected items are not of type mail message..");
                    }
                }
            }
            if (activeWindow is Microsoft.Office.Interop.Outlook.Inspector)
            {
                // its an inspector window
                Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
                Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem;
                CreateFormOrForm(mailItem);
            }

maybe this is of help for someone else ...

like image 50
Christian Casutt Avatar answered Sep 18 '22 01:09

Christian Casutt