Kefalas Savvas
Kefalas Savvas

Reputation: 49

where to put c# code to run on closing outlook

I have created an Outlook add-in and I want to run a couple of lines on closing of Outlook, but I cannot find where to put the code.

I tested ThisAddIn_Shutdown and Ribbon1_Unload events, but the debugger does not hit a breakpoint in either event.

Any suggestions or workarounds?

Upvotes: 1

Views: 471

Answers (1)

Lews Therin
Lews Therin

Reputation: 3777

You are correct about the ThisAddIn_Shutdown event:

The Shutdown event is raised only when the user disables the VSTO Add-in by using the COM Add-ins dialog box in Outlook. It is not raised when Outlook exits.

You want either the Quit event of the Microsoft.Office.Interop.Outlook.Application object or the Close event of the Microsoft.Office.Interop.Outlook.Explorer object.

See this documentation for more details.

Upvotes: 1

Related Questions