none
Excel 2007 Add.in (Vb.net) :How to find if outlook new mail window dialog box is opened from Excel ? RRS feed

  • Question

  • I have created an excel add-in.

    Whenever user opens Excel->Office Button -> Send -> Email ,a new mail window dialog is opened .

    I want to perform some operation in my excel add-in whenever a new mail window is opened from Excel.

    Is there a way to handle outlook event in excel add-in or

    to find if the new mail file dialog(outlook) is opened from excel?

    Tuesday, October 15, 2013 10:24 AM

Answers

  • Hi,

    According to your description, I think you want to capture the event when a new mail window popped up in the Excel workbook after you clicked the Send->Email button.

    However, I’m afraid there are no proper event in Outlook Application Events to do that.

    For a work around, I suggest you to pop up the new mail item in your Add-in instead of using the Send button. In this way, you could manipulate Outlook object in the workbook before you send it. You can also set the current Excel workbook as the attachment of the mail.

    To do this, we should add the reference of “Microsoft Outlook 12.0 Object Library” in the Excel add-in first.

    Here is a VB.net sample for your reference.

    Public WithEvents myItem As Microsoft.Office.Interop.Outlook.MailItem
    
    Private Sub SendEmail()
        Dim app As Microsoft.Office.Interop.Outlook.Application
        app = New Microsoft.Office.Interop.Outlook.Application()
    
        myItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
    
        myItem.To = "xxxx@xxxx.com"
    
        myItem.Subject = "Data files information"
        Dim sSource As String = "C:\Users\Documents\Book1.xlsx"
        Dim oAttachs As Microsoft.Office.Interop.Outlook.Attachments = myItem.Attachments
        Dim oAttach As Microsoft.Office.Interop.Outlook.Attachment
        oAttach = oAttachs.Add(sSource, , , )
    
        ' Display
        myItem.Display()
    
    End Sub
    


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 17, 2013 12:34 PM
    Moderator