-1

c# outlook open existing instance and get list of opened outlook windows to compose reply to of chosen window.

i am able to get outlook's existing instance but not sure how to approach its child windows and set reply to with existing email rather creating new mailitem

public static Outlook.Application OutlookInstance { get { Outlook.Application application = null;

            // Check whether there is an Outlook process running.
            if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
            {

                // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
                application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
            }
            else
            {

                // If not, create a new instance of Outlook and log on to the default profile.
                application = new Outlook.Application();
                Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
                nameSpace.Logon("", "", Missing.Value, Missing.Value);
                nameSpace = null;
            }

            // Return the Outlook Application object.
            return application;
        }
    }
Muhammad Adnan
  • 1,375
  • 6
  • 19
  • 40

1 Answers1

0

It looks like you are interested in the ActiveInspector method which return the topmost Inspector object on the desktop. Use this method to access the Inspector object that the user is most likely to be viewing. If no inspector is active, returns null (Nothing in VB.NET).

Also you may find the Inspectors property of the Application class helpful. It returns an Inspectors collection object that contains the Inspector objects representing all open inspectors.

 Dim myInspectors As Outlook.Inspectors  
 Dim x as Integer 
 Dim iCount As Integer 
 Set myInspectors = Application.Inspectors 
 iCount = Application.Inspectors.Count 
 If iCount > 0 Then 
   For x = 1 To iCount 
     MsgBox myInspectors.Item(x).Caption 
   Next x 
 Else 
   MsgBox "No inspector windows are open." 
 End If 

If you need to get the currently selected items in the Outlook Explorer window use the Selection object. See How to: Programmatically Determine the Current Outlook Item for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45