Class:EdInspectorEventClass
Public WithEvents myOlInspectors As Outlook.Inspectors
Public WithEvents myMail As Outlook.MailItem

Public Sub Initialize_handler()
Set myOlInspectors = Application.Inspectors
End Sub

Private Sub myOlInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
If (Inspector.CurrentItem.Class = olMail) Then
MsgBox ("You're in mail.")
Set myMail = Inspector.CurrentItem
End If
End Sub

Private Sub myMail_Close(Cancel As Boolean)
' do whatever you want
End Sub

In Module2:

Public myClass As EdInspectorEventClass
Sub DoSomething()
Set EdInspectorEventClass = New EdInspectorEventClass
EdInspectorEventClass.Initialize_handler
End Sub

To start things off the DoSomething procedure must be called to instantiate
an instance of the EdInspectorEventClass class and to call
EdInspectorEventClass.Initialize_handler. From there the code in
EdInspectorEventClass will run and handle any NewInspector event.

Of course you will also need to release your class at some point (set it to
Nothing). And the code as shown will handle one open Inspector at a time,
not multiple open Inspectors. For that you'd need to use a more complex
approach of wrapper classes stored in a collection.

Personally, if I was writing this and I wanted the code to start
automatically I'd put the Module2 code in the ThisOutlookSession class and
call DoSomething from the Application_Startup() event handler. I'd also
probably restructure it like this:

' move all this into ThisOutlookSession:
Public WithEvents myOlInspectors As Outlook.Inspectors
Public myInspectorsCollection As New Collection

Public Sub Initialize_handler()
Set myOlInspectors = Application.Inspectors
End Sub

Private Sub myOlInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
If (Inspector.CurrentItem.Class = olMail) Then
MsgBox ("You're in mail.")
Dim oInspClass As New EdInspectorEventClass
Set oInspClass.myMail = Inspector.CurrentItem
myInspectorsCollection.Add oInspClass
End If
End Sub

Class:EdInspectorEventClass
Public WithEvents myMail As Outlook.MailItem

Private Sub myMail_Close(Cancel As Boolean)
' do whatever you want
End Sub

That will let you handle item.Close() on multiple open Inspectors and the
collection will keep each Inspector and Mail item alive.

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

<landau@skiz.net> wrote in message
news:ed3ed638-e5c7-4ef9-b114-b6d040a4a5e3@b2g2000hsg.googlegroups.com...
> 'Hope I'm not pushing here :). So I'm taking small steps. I tried to
> write something to test to see if the current inspector was mail (as
> you suggested). I believe if I can get this down, the rest will be
> easy. I guess I'm not grok;ing the class thing. I took a C++ class a
> while back and was good at it. In this case, I'm not sure if the class
> gets instantiated with the "Set" command... and if so, what is its
> "handle" ?
>
> Class:EdInspectorEventClass
> Public WithEvents myOlInspectors As Outlook.Inspectors
> Public Sub Initialize_handler()
> Set myOlInspectors = Application.Inspectors
> End Sub
> Private Sub myOlInspectors_NewInspector(ByVal Inspector As
> Outlook.Inspector)
> If (Inspector.CurrentItem.Class = olMail) Then
> MsgBox ("You're in mail.")
> End If
> End Sub
>
> In Module2:
> Sub DoSomething()
> Set EdInspectorEventClass = Outlook.Inspectors
> EdInspectorEventClass.Initialize_handler ' *****This is where
> it fails and says object does not support this property.*****
> End Sub
>
>
06 Feb 2008Help writing a macro to move emails.landau@skiz.net
06 Feb 2008|- RE: Help writing a macro to move emails.Anand.V.V.N
22 Jan 2010|  \ imap move deleted email to TRASH in outlook.andre cloete
06 Feb 2008\ Re: Help writing a macro to move emails.Ken Slovak - [MVP - O...
06 Feb 2008   \ Re: Help writing a macro to move emails.landau@skiz.net
06 Feb 2008      \ Re: Help writing a macro to move emails.Ken Slovak - [MVP - O...
06 Feb 2008         \ Re: Help writing a macro to move emails.landau@skiz.net
07 Feb 2008            |- Re: Help writing a macro to move emails.landau@skiz.net
07 Feb 2008            \ Re: Help writing a macro to move emails.Ken Slovak - [MVP - O...
07 Feb 2008               \ Re: Help writing a macro to move emails.landau@skiz.net
07 Feb 2008                  \ Re: Help writing a macro to move emails.Ken Slovak - [MVP - O...
13 Mar 2008                     \ Re: Help writing a macro to move emails.sandeepthanki@gmail.com
Contact Us
All times are in (US) Eastern Daylight Time (GMT -4:00)