Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I created a project for addins using following link.
https://msdn.microsoft.com/en-us/library/office/ee941475%28v=office.14%29.aspx?f=255&MSPPError=-2147217396#BuildingNativeAddinforOL2010_CreatingaNativeAddin

My requirement is to get the emails selected by user on click of a button from addins tab and send that input to another dll. And i already created a addins tab and buttons in outlook using above shared link. Ours is a document storage management so users can be able to save the data from the outlook/word/excel.

Thanks,
Vijay

What I have tried:

I am new to the com interfaces, so i followed same that was shared in above link.
Posted
Updated 9-Feb-17 0:09am

1 solution

I have a little experience in add-ins with c#, but I believe that you will understand the concept.
I believe that you should use Microsoft.Office.Interop classes with COM to create it.

To find the current selected Microsoft.Office.Interop.Outlook.MailItem you can use this:

C#
Outlook.MailItem Email = null;
Outlook.Inspector actInspector = Outlook.Application.ActiveInspector();
if (actInspector == null)
{
    Outlook.Explorer explorer = Outlook.Application.ActiveExplorer();

    try
    {
        Email = explorer.GetType().InvokeMember("ActiveInlineResponse", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance |
                System.Reflection.BindingFlags.Public, null, explorer, null) as Outlook.MailItem;
    }
    finally
    {
        Marshal.ReleaseComObject(explorer);
    }
}
else
{
    try
    {
        Email = actInspector.CurrentItem as Outlook.MailItem;
    }
    finally
    {
        if (actInspector != null) Marshal.ReleaseComObject(actInspector);
    }
}


this came from
http://stackoverflow.com/questions/40973773/how-to-reliably-know-what-object-is-current-in-focus-outlook-window-i-e-an-e/40979666#40979666

To get all MailItem selectes in explorer you can use this:

C#
Outlook.Explorer explorer = null;
Outlook.Selection selection = null;

try
{
    explorer = Global.OutlookApp.ActiveExplorer();
    selection = explorer.Selection;

    //selection.Count;  --Example
    foreach (MailItem item in selection)
    {
        //item.Subject -- Example
    }
}
finally
{
    if (selection != null)
       Marshal.ReleaseCOMObject(selection);

    if (explorer != null)
       Marshal.ReleaseCOMObject(explorer);
}
 
Share this answer
 
Comments
Vijay533 9-Feb-17 6:21am    
Thank you very much for your suggestion Anderson Rissardi.
Vijay533 14-Feb-17 1:03am    
Hi Anderson Rissardi,
I tried to add the Microsoft.Office.Interop.Word.dll into my project and getting following error.
Error C1083: Cannot open type library file: 'c:\program files\microsoft visual studio 10.0\visual studio tools for office\pia\office14\microsoft.office.interop.word.dll': Error loading type library/DLL.
Anderson Rissardi 14-Feb-17 5:52am    
Make sure that you have Microsoft Office installed on the machine and that you also have Visual Studio Tools for Office
Vijay533 14-Feb-17 7:47am    
Yes i have installed MSOffice, I do have dll in my directory.
Anderson Rissardi 14-Feb-17 12:55pm    
You can try this 'Walkthrough'. https://msdn.microsoft.com/en-us/library/cc668191.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900