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
?
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With