NewMail Event - outlook VBA beginner

A

acces

Hi,
I'm really Outlook VBA beginner, it's different from Excel, where
have some experience...

Problem:
Example in VBA help "NewMail Event Example" doesn't work. What's wrong
Can enyone recommend me way how to learn Outlook VBA basic - rea
through VBA help is very lenghty.

How should I call myOlapp_NewMail() ?

Any help will be useful...
acces

PS. Sorry for my English, I hope you understand...
------------
Help example:
Dim WithEvents myOlApp As Outlook.Application

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

Private Sub myOlApp_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Set myExplorers = myOlApp.Explorers
Set myFolder
myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
myExplorers.Item(x).Display
myExplorers.Item(x).Activate
Exit Sub
End If
skipif:
Next x
End If
On Error GoTo 0
myFolder.Display
End Su
 
S

Sue Mosher [MVP]

Easiest solution: Change the name of the procedure from myOlapp_NewMail()
to Application_NewMail, move it to the ThisOutlookSession module, and
replace the myOlApp object with the intrinsic Application object:

Private Sub Application_NewMail()
Dim myExplorers As Outlook.Explorers
Dim myFolder As Outlook.MAPIFolder
Set myExplorers = Application.Explorers
Set myFolder =
myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
If myExplorers.Count <> 0 Then
For x = 1 To myExplorers.Count
On Error GoTo skipif
If myExplorers.Item(x).CurrentFolder.Name = "Inbox" Then
myExplorers.Item(x).Display
myExplorers.Item(x).Activate ' this is redundant
Exit Sub
End If

skipif:
Next x
End If

On Error GoTo 0
myFolder.Display
End Sub


See http://www.slipstick.com/dev/vb.htm#tutorials for tutorials and other
resources.
 

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