Log in

View Full Version : VBA rule setting



fahadakbar
05-17-2016, 07:36 AM
Hello,

I need help in setting a rule in Outlook through VBA.

I want to create a rule so that when an email arrives

1) from a specific person , say from Adam
2) specific subject , say hello
3) arrives with in workdays of the week (Monday to Friday)

then

Start an application (.exe file on c drive)

I can do all this by using "rules" option, except the timing condition (3rd , Monday-Friday)
so i need a vba code that can do the entire thing

Thank you so much for the help !

gmayor
05-17-2016, 08:53 PM
This is simple enough to achieve with a script associated with a rule to identify the incoming messages e.g.


Sub ProcessMessage(Item As Outlook.MailItem)
Dim iDay As Integer
iDay = Weekday(Item.ReceivedTime, vbMonday)
Select Case iDay
Case 1, 2, 3, 4, 5
MsgBox "It's a weekday"
'do weekday stuff
Case Else
MsgBox "It's weekend"
'do weekend stuff
End Select
lbl_Exit:
Exit Sub
End Sub

fahadakbar
05-18-2016, 10:40 AM
Hi Garahm,

Thanks a lot for the help. How do I associate this script with the rule ?

Much appreciate your help

Fahad

gmayor
05-18-2016, 08:38 PM
When you create the rule to process incoming messages running a script is one of the options available. Select the above script, which should have been copied to a module in Outlook VBA - see also http://www.gmayor.com/create_and_employ_a_digital_cert.htm