Automatically Run code in Outlook when new message received
I would like to configure something in Outlook so that every time a new message arrives in a certain folder it runs a script. I have a program to parse the subject of an e-mail but it has to do this manually. Is there anyway to automate this process so that once the e-mail comes in it will run my code. Another possible but less desired solution would be to have Outlook on a timer to run my code every so often.
Re: Automatically Run code in Outlook when new message received
there should be a message arrival event or similar that will run whenever a message arrives
Re: Automatically Run code in Outlook when new message received
Hit Alt-F11 keys or on outlook menu Tool -> Macro -> Visual Basic Editor
on the right panel there are two dropdown boxes, Select Application on the first dropdown. Select NewMail <Event> on the second drop down;
or copy paste this;
Code:
Private Sub Application_NewMail()
MsgBox ("new mail")
'insert your code here
End Sub
Re: Automatically Run code in Outlook when new message received
That is very close to what I am looking for but is there anyway to go one step further and only run when a message is received in a certain folder?
Re: Automatically Run code in Outlook when new message received
here's an idea I haven't tested this code,
Code:
Dim objNS As NameSpace
Dim objPF As MAPIFolder
Dim objitem As Object
'Set objNS = Application.GetNamespace("MAPI")
'Set objPF = objNS.Folders("YourFolder")
Set objitem = GetCurrentItem()
If objitem.Parent = "<YourFolder>" Then
:
'insert your code here
:
End If