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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vba coding with Outlook

Status
Not open for further replies.

dreammaker888

Programmer
Jul 31, 2007
44
US
In the Outlook vba help file, it said . . .

"This Microsoft Visual Basic/Visual Basic for Applications (VBA) example displays the Inbox folder when a new e-mail message arrives. 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 Microsoft Outlook.
"

The following is what I wrote in code and I put it in Class1 of the class module:

Code:
Public WithEvents myOlApp As Outlook.Application

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


Private Sub myOlApp_NewMail()
    Dim myExplorers As Outlook.Explorers
    Set myExplorers = myOlApp.Explorers
    Dim myItem As Outlook.MailItem

    Set myItem = myOlApp.ActiveInspector.CurrentItem
    If myItem.Subject = "Testing" Then
        MsgBox "This message is a test message."
    End If

End Sub

When I receive a new email, it doesn't seem to activate this block of routine.

What am I doing wrong?

I am not familiar with class module at all.

Thanks.

dmk
 
and the Initialize_handler routine must be called before the event procedure can be called
Did you call this procedure before receiving the new email ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I thought that it was self-activated when I put it in the initialize_handler sub.

How do I call it before receiving emails?

Or should I put "Set myOlApp = CreateObject("Outlook.Application")" within the myOlApp_NewMail sub?

dmk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top