I have an vba script on outlook that reads a email message for keywords and outputs it to a csv file. The script works find if the email is addressed directly to me but the script breaks if it is a forwarded message from a friend. Any help is appreciated to edit the script to run properly when it is forwarded
Public Sub EidInfo(Item As Outlook.MailItem)
Dim CurrentMessage As MailItem
Dim MsgBody As String
Dim SearchPos As String
Dim SearchMsg(11) As String
Dim SearchStr(11) As String
Dim StartPos As Integer
Dim EndPos As Integer
Dim LineMsg As String
Set CurrentMessage = Item
MsgBody = CurrentMessage.HTMLBody
SearchStr(1) = "Requester "
SearchStr(2) = "Flight "
SearchStr(3) = "Request Type:-"
SearchStr(4) = "Summary : "
SearchStr(5) = "Description : "
SearchStr(6) = "Reason : "
SearchStr(7) = "Number : "
SearchStr(8) = "From Date : "
SearchStr(9) = "To Date : "
SearchStr(10) = "Number of Days : "
SearchStr(11) = "Country : "
EndPos = 1
For i = 1 To 11
StartPos = InStr(EndPos, MsgBody, SearchStr(i), vbTextCompare) + Len(SearchStr(i))
If i = 1 Then
EndPos = StartPos + 15
ElseIf i = 2 Then
EndPos = InStr(StartPos, MsgBody, ".", vbTextCompare)
ElseIf i = 11 Then
EndPos = InStr(StartPos, MsgBody, "<BR>", vbTextCompare)
Else
EndPos = InStr(StartPos, MsgBody, "<BR>" + SearchStr(i + 1), vbTextCompare)
End If
SearchMsg(i) = Mid(MsgBody, StartPos, EndPos - StartPos)
SearchMsg(i) = Replace(SearchMsg(i), "<BR>", " ")
SearchMsg(i) = Replace(SearchMsg(i), ",", ".")
Next i
If Dir("D:\EidFile.csv") = "" Then
Open "D:\EidFile.csv" For Output As #1
LineMsg = "Request Time,"
For i = 1 To 11
LineMsg = LineMsg + Replace(SearchStr(i), ":", " ")
If i < 11 Then LineMsg = LineMsg + ","
Next i
Print #1, LineMsg
LineMsg = ""
Else
Open "D:\EidFile.csv" For Append As #1
End If
LineMsg = CurrentMessage.ReceivedTime
LineMsg = LineMsg + ","
For i = 1 To 11
LineMsg = LineMsg + SearchMsg(i)
If i < 11 Then LineMsg = LineMsg + ","
Next i
Print #1, LineMsg
Close #1
End Sub