none
Is it possible to capture the Outlook client startup or close event? RRS feed

  • Question

  • I am try to capture the item add/change/delete event using VB.NET

    It works fine with the following code:

      Private Sub SetOutlookEvents()
           
            Dim notes As Outlook.Items = comm.oAppNS().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderNotes).Items
            AddHandler notes.ItemAdd, AddressOf ItemAddNote
            AddHandler notes.ItemChange, AddressOf ItemChangeNote
            AddHandler notes.ItemRemove, AddressOf ItemRemove
           
        End Sub

    However, if I close the Outlook client and open it again, the events are not fired anymore.

    Is it possible to capture the Outlook startup event so that I can call my "SetOutlookEvents" to add the handler again when user start the Outlook client?

    Regards,

    CowCow

    Wednesday, March 19, 2014 12:18 PM

Answers

  • Hello CowCow,

    You need to declare the notes object at the class level, not method.

    Wednesday, March 19, 2014 12:23 PM
  • You can use the Startup and Quit events of the Application class from the Outlook object model. Also you may be interested in the MAPILogonComplete event which is fired after the user has logged onto the system (into the mail profile).

    Note, VSTO provides the ThisAddin_Startup and ThisAddin_Shutdown event handlers out of the box.

    Wednesday, March 19, 2014 12:29 PM
  • Yes, that's. The Outlook object model is identical for all kind of applications.
    Wednesday, March 19, 2014 10:25 PM
  • Most probably the Startup event is not fired because Outlook is already started (too late to subscribe).

    Why do you need to subscribe to the setup events if you develop a standalone application?

    Note, you automate Outlook in the code, so you decide when you need to start or close it.

    Thursday, March 20, 2014 12:16 PM

All replies

  • Hello CowCow,

    You need to declare the notes object at the class level, not method.

    Wednesday, March 19, 2014 12:23 PM
  • You can use the Startup and Quit events of the Application class from the Outlook object model. Also you may be interested in the MAPILogonComplete event which is fired after the user has logged onto the system (into the mail profile).

    Note, VSTO provides the ThisAddin_Startup and ThisAddin_Shutdown event handlers out of the box.

    Wednesday, March 19, 2014 12:29 PM
  • But I am not using AddIn. It's a standalone vb.net app. Is that possible?
    Wednesday, March 19, 2014 10:17 PM
  • Yes, that's. The Outlook object model is identical for all kind of applications.
    Wednesday, March 19, 2014 10:25 PM
  • I have done some researches on internet. They all mentioned Add-In regarding this ThisAddin_Startup.

    How can we capture this event (ThisAddin_Startup) in our Windows Form Application?

    Thursday, March 20, 2014 12:57 AM
  • I try this:

     Dim WithEvents myOApp As Outlook.Application  = New Outlook.Application

      Private Sub myOApp_Quit() Handles myOApp.Quit
            MsgBox("Outlook quit")
        End Sub

      
        Private Sub myOApp_Startup() Handles myOApp.Startup
            MsgBox("Outlook start")
        End Sub

    However, I can see the popup when I quit Outlook. But I don't see the popup when I start  Outlook.

    The myOApp_Startup is not work.

    I think i better use a timer to check the outlook process id very 30 sec... It's more reliable.

    Thanks,

    Cowcow.

    Thursday, March 20, 2014 1:54 AM
  • Hello Cowcow,

    I'd recommend using debug statements instead of message box (see System.Diagnostics.Debug). Did you try to debug the code?

    As I already wrote, also you can try to use the MAPILogonComplete event of the Application class. 

    Thursday, March 20, 2014 7:07 AM
  • Thank you for  your recommendation 

    I tried all these, but only the myOApp_Quit is called when I exit Outlook. The other never calls.

    What does it mean "MAPILogonComplete"?

    I don't need to login. I using start Outlook, and then check email and create some appointments. I don't need to login.

    ======================

    Private Sub myOApp_ItemLoad(Item As Object) Handles myOApp.ItemLoad
            Debug.Print("Outlook myOApp_ItemLoad")
        End Sub

        Private Sub myOApp_Quit() Handles myOApp.Quit
            Debug.Print("Outlook quit")
        End Sub



        Private Sub myOApp_Startup() Handles myOApp.Startup
            MsgBox("Outlook start")
        End Sub

        Private Sub myOApp_MAPILogonComplete() Handles myOApp.MAPILogonComplete
            Debug.Print("Outlook myOApp_MAPILogonComplete")
        End Sub

    ==================

    Thursday, March 20, 2014 9:07 AM
  • It comes from VSTO, not Outlook. In a standalone application you should use events that come from the Outlook object model. So, the Startup or MAPILogonComplete events are suitable.  
    Thursday, March 20, 2014 12:12 PM
  • Most probably the Startup event is not fired because Outlook is already started (too late to subscribe).

    Why do you need to subscribe to the setup events if you develop a standalone application?

    Note, you automate Outlook in the code, so you decide when you need to start or close it.

    Thursday, March 20, 2014 12:16 PM