You would need to put the cursor in the Initialize_Handler() procedure and
press F5 to run the code to initialize the event handler manually to test
the code. An item would need to be open at that time.
To make this automatic and initialized on Outlook startup you would need to
add additional code. This code in ThisOutlookSession would run on Outlook
startup and initialize the needed event handlers for that:
Public WithEvents colInspectors As Outlook.Inspectors
Public WithEvents myInspector As Outlook.Inspector
Private Sub Application_Startup()
Set colInspectors = Application.Inspectors
End Sub
Private Sub col_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olMail Then ' only for mail items
Set myInspector = Inspector
End If
End Sub
Private Sub myInspector_Close()
If myInspector.CurrentItem.Saved = False Then
myInspector.CurrentItem.Save
End If
Set myInspector = Nothing
End Sub
This would check for Saved on each mail item when it's closed. It would only
handle 1 open mail item at a time, and it would only handle mail items.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
"rattanjits" <rattanjits.3wiysa.RemoveThis@no-spam.invalid> wrote in message
news:rattanjits.3wiysa@no-spam.invalid...
>
> The Outlook developer reference for MailItem.Close event includes the
> following example to save an item without prompting the user:
>
> Public WithEvents myItem As Outlook.MailItem
> Public Sub Initalize_Handler()
> Set myItem = Application.ActiveInspector.CurrentItem
> End Sub
> Private Sub myItem_Close(Cancel As Boolean)
> If Not myItem.Saved Then myItem.Save
> End Sub
>
> I copied the example into Thisoutlooksession - and editted and closed a
> message - but it did not run. I have no knowledge of using Outlook
> events (other than events in the Application class which run
> automatically). Please advise.
>
>
> --
> rattanjits
> http://forums.slipstick.com/
>