|
-
Jan 27th, 2011, 03:12 PM
#1
Thread Starter
New Member
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.
-
Jan 27th, 2011, 03:46 PM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 27th, 2011, 04:55 PM
#3
Lively Member
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
-
Jan 28th, 2011, 09:05 AM
#4
Thread Starter
New Member
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?
Last edited by dicepackage; Jan 28th, 2011 at 09:09 AM.
-
Jan 29th, 2011, 01:45 PM
#5
Lively Member
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|