Link to home
Start Free TrialLog in
Avatar of karthik80c
karthik80cFlag for United States of America

asked on

How to get the date mentioned in the email into the VBA script in Outlook??

In outlook, I have created a rule that executed when I receive mail and it will create the appointment on outlook calendar with details from the  mail. In that I need to get the date and time mentioned in the mail body as the date of appointment created in outlook calendar.
Avatar of Rgonzo1971
Rgonzo1971

Hi,

it depends how the mail boy is constructed and will it always stay the same

EDIT could you send a dummy email body

Regards
Avatar of karthik80c

ASKER

Mail Body:


Transaction Name: 104 Horne Street

Contact Name: Wade Short

Email:

Phone: 0409696155

Inspection Date: 14-Aug-2015 18:30:00

Outcome Result:

meetingRequest.Categories = email.Categories
meetingRequest.body = email.body
meetingRequest.Subject = email.Subject
meetingRequest.Location = email.Subject
 meetingRequest.Start = 
meetingRequest.Duration = 60
meetingRequest.ReminderMinutesBeforeStart = 45
meetingRequest.ReminderSet = True

Open in new window


Here I need to use the Inspection date and time.
See example

Sub macro2()

itemBody = "Transaction Name: 104 Horne Street" & vbCrLf & _
            "Contact Name: Wade Short" & vbCrLf & _
            "Email:" & vbCrLf & _
            "Phone: 0409696155" & vbCrLf & _
            "Inspection Date: 14-Aug-2015 18:30:00" & vbCrLf & _
            "Outcome Result:"
            
aText = Split(itemBody, vbCrLf)
aTextTmp = Filter(aText, "Inspection Date:")
aInspDate = Split(aTextTmp(0), " ")
dtInspDate = DateValue(aInspDate(2))
dtInspTime = TimeValue(aInspDate(3))

End Sub

Open in new window

It shows compiler error as "Expected Array" in line 12, 13, 14 on the above code.
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried the following code to assign date and time, it tooks the date but not time.

meetingRequest.Start = dtInspDate + dtInspTime 

Open in new window


Instead of above i try the following, it works good.

meetingRequest.Start = dtInspDate + #11:00:00 AM# 

Open in new window


I need the help in time part.
pls try to add the two thing before assigning to start

dtInspDateTime = dtInspDate + dtInspTime
meetingRequest.Start = dtInspDateTime
I tried the above code, but it doesn't work.
Could you show me the result of the to msgboxes

dtInspDateTime = dtInspDate + dtInspTime
MsgBox dtInspDateTime
myItem.Start = dtInspDateTime
MsgBox myItem.Start
User generated image
I got only one msgbox. Then it shows Type mismatch error on "meetingRequest.Start = dtInspDateTime"
then try

aInspDate = Split(aTextTmp(0), ": ")
dtInspDate = DateValue(aInspDate(1))
dtInspTime = TimeValue(aInspDate(1))
MsgBox dtInspDate & vbCrlf & dtInspTime
dtInspDateTime = dtInspDate + dtInspTime
MsgBox dtInspDateTime
myItem.Start = dtInspDateTime
it shows Type mismatch error