Extract Dates for Appointment Item in Body of email

Status
Not open for further replies.

Bob Weidman

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Here is my script that runs as a rule as soon as new email's come into the account. What I need is to have the start time and end time being defined in the body of the email. This code does work just need the Dates fixed for the appointment item.

Sub RunscriptMacro(MyMail As MailItem)
NewMeetingRequestFromEmail incoming:=MyMail
End Sub


Sub NewMeetingRequestFromEmail(incoming As MailItem)
Dim objAppt As Outlook.AppointmentItem
Set objAppt = Application.CreateItem(olAppointmentItem)

objAppt.Subject = incoming.Subject
objAppt.Location = incoming.Subject
objAppt.Body = incoming.Body
objAppt.Start = incoming.ReceivedTime
objAppt.End = DateSerial(Year(Now), Month(Now), Day(Now) + 7)



' when is the start date? I want it to be from a datefield in the body of the email after the text "Event Start:"
' when is the end date? I want it to be from a datefield in the body of the email after the text "Event End:"

' save and leave
objAppt.Save
Set objAppt = Nothing
End Sub
 

Bob Weidman

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
When I try to implement that then nothing works. Call me confused. I made sure that VBScript Expressions 5.5 is on.
 

Bob Weidman

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
This is what I had put into my code that I wrote above in order to just see if I can change the location in the appointment item from a string in the body of the email.

With Reg1.Pattern = "Location\s*[:]+\s*(\w*)\s*"
.Global = True
End With
If Reg1.test(incoming.Body) Then
Set M1 = Reg1.Execute(incoming.Body)
For Each M In M1
objAppt.Location = M.SubMatches(1)
Next
End If
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
BTW, is there a reason you are using 2 macros instead of just the second one?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This works. I think the problem was because you need to use two sets of () in the pattern - they don't have to both be together like i did it, but the submatches gets the pattern inside the second set.

Code:
Sub RunscriptMacro(MyMail As MailItem)
NewMeetingRequestFromEmail incoming:=MyMail
End Sub


Sub NewMeetingRequestFromEmail(incoming As MailItem)
Dim objAppt As Outlook.AppointmentItem
Dim strLoc As String
Dim Reg1 As RegExp
    Dim M1 As MatchCollection
    Dim M As Match

Set objAppt = Application.CreateItem(olAppointmentItem)
    Set Reg1 = New RegExp
   
With Reg1
  .Pattern = "Location\s*[:]+\s*((\w*))\s*"
.Global = True
End With
If Reg1.test(incoming.Body) Then
Set M1 = Reg1.Execute(incoming.Body)
For Each M In M1
strLoc = M.SubMatches(1)
Next
End If
With objAppt

.Subject = incoming.Subject
.Location = incoming.Subject
.Body = incoming.Body
.Start = incoming.ReceivedTime
.End = DateSerial(Year(Now), Month(Now), Day(Now) + 7)
.Location = strLoc
.Display 'Save
End With

Set objAppt = Nothing
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
this works with 1 set of ()
Code:
With Reg1
  .Pattern = "Location\s*[:]+\s*(\w*)\s*"
.Global = True
End With
If Reg1.test(incoming.Body) Then
Set M1 = Reg1.Execute(incoming.Body)
For Each M In M1
strLoc = M
Next
End If
 

Bob Weidman

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Thank you so much Diane for your help! This does indeed work. I changed the .Display to .Save
Now the next part I need to do is probably set-up CASE statements that would then take Date strings out of the body of the email and put them into the .Start and .End time of the AppointmentItem. Starting that process now. I'll let you know how that goes.
 

Bob Weidman

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Here is my Case statements but it did not create the Appointment Item

For i = 1 To 3
With Reg1
Select Case i
Case 1
.Pattern = "(Location\s*[:]([\w-\s]*)\s*)\n"
.Global = False
Case 2
.Pattern = "(Start[:][\d]+[\/-][\d]+[\/-][\d])\n"
.Global = False
Case 3
.Pattern = "(End[:][\d]+[\/-][\d]+[\/-][\d])\n"
.Global = False
End Select

End With
If Reg1.Test(incoming.Body) Then
Set M1 = Reg1.Execute(incoming.Body)
For Each M In M1
strLoc = M.SubMatches(1)
Next
End If

Next i
With objAppt

.Subject = incoming.Subject
.Location = incoming.Subject
.Body = incoming.Body
.Start = incoming.ReceivedTime
.End = DateSerial(Year(Now), Month(Now), Day(Now) + 7)
.Location = strLoc
.Start = strLoc
.End = strLoc
.Save 'Save
End With
 

Forum Admin

Senior Member
Not sure how this go missed earlier - Did it not create the appointment or not populate the fields?

An FYI - one problem is probably here:
strLoc = M.SubMatches(1)
The 1 in submatches indicated the set of () to use - but it starts at 0. So
.Pattern = "(End[:][\d]+[\/-][\d]+[\/-][\d])\n"
would use strLoc = M.SubMatches(0)

if you just wanted the date values, you'd use this as the pattern
.Pattern = "(End[:]([\d]+[\/-][\d]+[\/-][\d]))\n"
and keep the submatches(1)

Debug.print can be your friend when testing macros - use
strLoc = M.SubMatches(1)
debug.print strLoc

then show the immediate window (Ctrl+G or look on the View menu). if the value of strLoc isn't written to the immediate window, the pattern is wrong.

another problem is here:
.Subject = incoming.Subject
.Location = incoming.Subject
.Body = incoming.Body
.Start = incoming.ReceivedTime
.End = DateSerial(Year(Now), Month(Now), Day(Now) + 7)
.Location = strLoc
.Start = strLoc
.End = strLoc

you're writing then overwriting the start, end and location fields.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
J Outlook 2013 Extract Flag Completed dates to Excel Macro Outlook VBA and Custom Forms 16
N Extract Outlook emails to excel Outlook VBA and Custom Forms 2
M Extract all links from Outlook email, send to Excel Using Outlook 2
T Extract Data From Outlook Tasks Using Outlook 0
T Extract Data From Outlook Tasks Using Outlook 0
V extract users of a particular department Outlook VBA and Custom Forms 1
S How to extract mail items from multiple folders and shared mailboxes? Outlook VBA and Custom Forms 0
K Extract email address from body and auto-reply outlook Using Outlook 1
R Trying to extract information between two symbols from outlook subject Using Outlook 2
K Extract email to excel from a specific sender Outlook VBA and Custom Forms 3
O VBA to extract email (fields and body) to Excel Outlook VBA and Custom Forms 14
P Recover / Extract Rules from standalone PST file creating RWZ file Using Outlook 2
D Need to extract a line from a word attachment, and add it to the subject line Outlook VBA and Custom Forms 3
E Extract excel files from outlook Outlook VBA and Custom Forms 2
K extract certain text from an Outlook Email Message Outlook VBA and Custom Forms 2
D VBA Script to extract text matching specific criteria Outlook VBA and Custom Forms 1
M Extract text in existing message body for use in newmail items Using Outlook 17
M HELP--Extract Data from 2003 outlook transfer to excel spreadsheet Using Outlook 1
M VBA Code to extract data from an Outlook Form Using Outlook 0
M Extract attachments with a script Using Outlook 0
M HELP - Can't open outlook... How can I extract my Emails that I had in folders Using Outlook 3
H Extract emails from Outlokk 2007 email body Using Outlook 0
K Extract Global Address List Using Outlook 1
E I am trying to extract the email adress's i have in outlook. These are not saved 'contacts' these are ones from auto fill. When i open up an email, an Using Outlook 1
L How to extract table format of Task Item if its body contains formatted table. Exchange Server Administration 1
R Saving Outlook Email As Text File Extract Outlook VBA and Custom Forms 2
N Programming to extract automatically extract attachments Outlook VBA and Custom Forms 3
S How to extract outlook calendar data. Outlook VBA and Custom Forms 3
? outlook attachment Extract File ??? Outlook VBA and Custom Forms 1
D Extract Data from OST File Using Outlook 2
N How to extract date and time stamp from messsages Outlook VBA and Custom Forms 6
V Extract Subject,Sent From, Message from mailbox to Excel Outlook VBA and Custom Forms 5
S Automatically extract attachments? Outlook VBA and Custom Forms 1
I How to extract email addresses from TO or CC line of a particular email Outlook VBA and Custom Forms 2
L dynamic and static dates in Outlook contact "notes" ie. body Using Outlook 2
I Help with dates in task list. Using Outlook 5
Z Outlook for G Suite emails showing wrong dates Using Outlook 4
Z Outlook 2013 Gmail IMPA emails not showing dates only showing times Using Outlook 1
O Outlook 2016 follow-up flags--how can I add dates? Using Outlook 1
L Entering dates in Contacts and Calendar Using Outlook 4
O highlighted dates in Yearly View for Outlook 2010 Using Outlook 1
1 Incorrect dates in sent folder Using Outlook 4
C Many Expiration Dates in Custom Form Using Outlook 1
N To Do bar showing incorrect due dates on tasks Using Outlook 4
O automate dates in outlook template Using Outlook 1
R adding anniversary dates in outlook Using Outlook 2
B Birthday dates automatically (and improperly) placed in Birthday Details Using Outlook 2
D Task Start and Due Dates Using Outlook 3
T Conditional dates in Outlook Calendar Exchange Server Administration 1
C Dates changes to 1899 when Tab key hit in Time... Using Outlook 3
Similar threads


















































Top