How to automatically show an email when it arrives?

  • Thread starter Richard Lewis Haggard
  • Start date
R

Richard Lewis Haggard

Is there a way to automatically display an email message when it arrives?

Every once in a while, I get buried in programming and don't notice the new
email icon in the tray. I tried enabling the new mail message box thing but
found it to be a time waster. I was thinking that a simple automatic display
of the email itself might be useful - except that I can't quite figure out
how to accomplish this task. Would someone be so kind as to point me in the
right direction?
 
M

Michael Bauer

Hi Richard,

the Items.ItemAdd event for the Inbox is what you are looking for. If
the type of the object passed in is an Outlook.MailItem then call it´s
Display method.
 
P

peter

Please could you write clearly step by step
???
Michael Bauer píše:
Hi Richard,

the Items.ItemAdd event for the Inbox is what you are looking for. If
the type of the object passed in is an Outlook.MailItem then call it´s
Display method.
 
M

Michael Bauer

Hi Peter,


'<DieseOutlookSitzung>
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Set Items = Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
Item.Display
End If
End Sub
'</DieseOutlookSitzung>


--
Viele Grüße
Michael Bauer


peter said:
Please could you write clearly step by step
???
Michael Bauer píše:
 
R

Richard Lewis Haggard

Wonderful! Thank you very much. However, I do have a small problem with it -
it only monitors the contents of a single folder. My email contains some 30
odd folders which get loaded automatically via a fairly complicated set of
Rules. Is there some way to do the same sort of thing generically, or am I
reduced to duplicating this for each and every one of the 30+ folders?
 
M

Michael Bauer

Hi Richard,

in this case I would use a class module, one instance for each folder.
Each instance needs a reference on the folder items, which you can get
easily with Sue´s function, please download it yourself.


'<ThisOutlookSession>
Private m_oColl As VBA.Collection

Private Sub Application_Startup()
Set m_oColl = New VBA.Collection
AddFolderItems "personal store\inbox"
AddFolderItems "personal store\inbox\test1"
AddFolderItems "personal store\inbox\test2"
End Sub

Private Sub AddFolderItems(sFolderPath As String)
Dim oFld As Outlook.MAPIFolder
Dim oItems As cItems

' Call GetFolder from Sue Mosher,
http://www.outlookcode.com/d/code/getfolder.htm
Set oFld = GetFolder(sFolderPath)
If Not oFld Is Nothing Then
Set oItems = New cItems
oItems.Init oFld.Items
m_oColl.Add oItems
End If
End Sub
'</ThisOutlookSession>

' <cItems.cls>
Option Explicit

Private WithEvents Items As Outlook.Items

Public Sub Init(oItems As Outlook.Items)
Set Items = oItems
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
Dim oMail As Outlook.MailItem

If TypeOf Item Is Outlook.MailItem Then
Set oMail = Item
oMail.Display
End If
End Sub
' </cItems.cls>
 

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

Top