Search of an event fired immediate before Quit-event

  • Thread starter Peter Ostermann
  • Start date


Peter Ostermann

Hi NG,

as everybody knows minimizing Outlook 2007 creates a little Icon in the
system-tray, and it is recommendable to minimize it, every time after usage,
because it takes a while to start Outlook again after closed.

The user nevertheless often falls victim his habit, to close applications
after usage. I try to show a prompt before closing to stop "Quit", but once
the Quit event is released it seems that it can't be stopped anymore, even
though the prompt still happens.
Here the code:

Private Sub Application_Quit()
OK = MsgBox("Really want to quit?", vbYesNo, "Closing Outlook")
If OK <> 6 _
OK = MsgBox("Quit stopped, minimized", vbYes, "Closing Outlook")
Call MinimizeActiveWindow
End If
OK = MsgBox("Test completed", vbYes, "Closing Outlook")
MsgBox "Goodbye, " & Application.GetNamespace("MAPI").CurrentUser
End Sub

Sub MinimizeActiveWindow()
OK = MsgBox("There is no window anymore that could be minimized", vbYes,
"Closing Outlook")
ActiveWindow.WindowState = olMinimized
End Sub

How would a "Quit-stop" look like to solve this problem?

Peter Ostermann



Ken Slovak - [MVP - Outlook]

You can't stop it. By the time Application.Quit fires all the Outlook
objects are already out of scope and have been released. There is no
BeforeQuit event and the BeginShutdown event in COM addins has no Cancel
argument to stop a shutdown.

Peter Ostermann

Thanks, Ken,

I understand.
May be there is a more simple workaround possible:
How can I disable the cross at right hand side of the Outlook
window bar?


Ken Slovak - [MVP - Outlook]

You can't do that either.

I suppose you could by getting the window that displays that control using
Win32 API calls and then find the control and send it a Windows message to
disable itself. You might have to change the window type displayed by
Outlook to not show the Close button, usually you lose the minimize and
resize controls too when you do that, and I'm not sure that Outlook would
like you messing around with it's dialog window type.

But I guess you could try it.


Jun 5, 2012
Reaction score
Hello Michael,

I do not see an email posted for you here and I am attempting to use this same code to move objects from one folder to another when a user chooses to exit/quit Outlook. Would your application work in this instance?


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question