Create Calendar Alert Event form Mail Subject line?

Status
Not open for further replies.

Jatin

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
Hi there,

What I am trying to do is create an calendar event from mail subject line as below.
If I receive any mail with subject line as Due Date:01/01/2015 it should create a event in calendar and also alert me whenever that date and time occurs.
Is this possible by rule or macro? Any help would be much appreciated.

Thanks,
Jatin
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You can't use a rule by itself, but can use a script with a rule to find messages which might match then process it more with a script. A regex example is here: http://www.slipstick.com/developer/run-a-script-rule-autoreply-using-a-template/

I didn't test it, but this should be close:
Code:
Sub ConvertMailtoTask(Item As Outlook.MailItem)
Dim objAppt As Outlook.appointmentItem
Dim Reg1 As Object
Dim M1 As Object
Dim M As Object
Dim strDate
Set Reg1 = CreateObject("VBScript.RegExp")

With Reg1
.Pattern = "Due Date[:]([\d/]*)"
End With

If Reg1.Test(Item.Subject) Then

Set M1 = Reg1.Execute(Item.Subject)
For Each M In M1
strDate = M.SubMatches(0)
Next
End If

Set objAppt = Application.CreateItem(olappointmentItem)
With objAppt
.Subject = Item.Subject
.StartDate = strdate
.Body = Item.Body
.ReminderSet = True
.ReminderTime = strdate
.Save
End With
Set objappt = Nothing
End Sub
 

Jatin

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
Thanks Diane for the quick reply.
Sorry small change in the question. Actaully date comes in Message Body and in below format.
The bla blaa milestone is due in 2 days on Friday, 27 February 2015.

Can we do this using above script.

Regards,
Jatin

You can't use a rule by itself, but can use a script with a rule to find messages which might match then process it more with a script. A regex example is here: http://www.slipstick.com/developer/run-a-script-rule-autoreply-using-a-template/

I didn't test it, but this should be close:
Code:
Sub ConvertMailtoTask(Item As Outlook.MailItem)
Dim objAppt As Outlook.appointmentItem
Dim Reg1 As Object
Dim M1 As Object
Dim M As Object
Dim strDate
Set Reg1 = CreateObject("VBScript.RegExp")

With Reg1
.Pattern = "Due Date[:]([\d/]*)"
End With

If Reg1.Test(Item.subject) Then

Set M1 = Reg1.Execute(Item.Body)
For Each M In M1
strDate = M.SubMatches(0)
Next
End If

Set objAppt = Application.CreateItem(olappointmentItem)
With objAppt
.Subject = Item.Subject
.StartDate = strdate
.Body = Item.Body
.ReminderSet = True
.ReminderTime = strdate
.Save
End With
Set objappt = Nothing
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
As long as you can get a unique pattern, you can do it.

This is where we grab and process the date:
With Reg1
.Pattern = "Due Date[:]([\d/]*)"
End With

If Reg1.Test(Item.Subject) Then

Set M1 = Reg1.Execute(Item.Subject)
For Each M In M1
strDate = M.SubMatches(0)
Next

you need to change the pattern - as long as only the date and day count change, you can do this.
milestone is due in 2 days on Friday, 27 February 2015.

one option is
.Pattern = "milestone is due in ([\d/]*) days"
then add it to date or now to get the start (or due) date.

.StartDate = date + strdate

that might be easier than grabbing the date.

Updated;: you also need to change Item.Subject to Item.body in the Reg1 lines.
 

Jatin

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
Thanks Diane,

Now my code looks as below if I am reading date from mail body not subject


Sub ConvertMailtoTask(Item As Outlook.MailItem)
Dim objAppt As Outlook.AppointmentItem
Dim Reg1 As Object
Dim M1 As Object
Dim M As Object
Dim strDate
Set Reg1 = CreateObject("VBScript.RegExp")

With Reg1
.Pattern = "milestone is due in ([\d/]*) days"
End With

If Reg1.Test(Item.Body) Then

Set M1 = Reg1.Execute(Item.Body)
For Each M In M1
strDate = M.SubMatches(0)
Next
End If

Set objAppt = Application.CreateItem(olAppointmentItem)
With objAppt
.Subject = Item.Subject
.StartDate = Date + strDate
.Body = Item.Body
.ReminderSet = True
.ReminderTime = strDate
.Save
End With
Set objAppt = Nothing
End Sub
 
Status
Not open for further replies.
Top