• Subject: Re: Vba coding with Outlook
  • Author: SvenC
  • Date: 14 Apr
  • References: 1
Hi dmkAlex,

> 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?

You don't need an additional Application object in Outlook VBA.
Open the VBA editor. Select Application in the top left combobox.
Select NewMail from the top right combobox. Put your
myOlApp_NewMail code in that event handler.

Your above approach would only be necessary when you code runs
outside of Outlook.

--
SvenC
13 AprVba coding with Outlook.dmkAlex
14 Apr|- Re: Vba coding with Outlook.SvenC
14 Apr\ Re: Vba coding with Outlook.JP
15 Apr   \ Re: Vba coding with Outlook.dmkAlex
16 Apr      |- Re: Vba coding with Outlook.SvenC
16 Apr      \ Re: Vba coding with Outlook.JP
All times are in (US) Eastern Daylight Time (GMT -4:00)