Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook VBA...beforeclose event? 1

Status
Not open for further replies.

Turpis

Programmer
Apr 16, 2002
151
Is there such a thing as a beforeclose event in Outlook?

I program in Excel quite a bit and if I wanted to have Excel prompt me to confirm if I really wanted to close Excel or not I would put in the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ans = MsgBox("Are you sure you want to exit?", vbYesNo, _
"Close Application?")

If ans = vbNo Then
Cancel = True
End If
End Sub

I put this code into the Application_Quit event in Oulook and Outlook quits first and then asks the msgbox question. How can I create a beforeclose event?

Charles
Well I want to do this to my Outlook because I open and close many files all day long and I have a five button Microsoft trackball with one of the buttons program to close active application. Sometimes (about 3-4 times a week) I accidentally end up closing Outlook and it is starting to really get me mad.
 
Just wondering if anybody has some thoughts on this?

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
Hi T,
Right out of Outlook HELP...
Code:
Quit Event
See Also Applies To Example Specifics 
Occurs when Microsoft Outlook begins to close. This event is not available in VBScript.

Sub object_Quit()

object   An expression that evaluates to an Application object.

Example
This example displays a farewell message when Microsoft Outlook exits. The sample code must be placed in a class module, and the Initialize_handler routine must be called before the event procedure can be called by Outlook.

Dim WithEvents myOlApp As Outlook.Application

Sub Initialize_handler()
    Set myOlApp = CreateObject("Outlook.application")
End Sub

Private Sub myOlApp_Quit()
    MsgBox "Goodbye, " & Application.GetNamespace("MAPI").CurrentUser
End Sub
Is this what you need?

Skip,
Skip@TheOfficeExperts.com
 
Thanks Skip! I just look things up wrong or something. I never seem to find what I am looking for in the Help. This is exactly what I was looking for.

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top