Extracting part of an Outlook item
I have one Outlook Item which has lots of messages in the body.
Is it possible to extract only the last message? Using Left function maybe?
Example of a body that has two messages (I need to extract just the first message)
**From: email@example.com To: firstname.lastname@example.org Subject: Testing Hi, this is FIRST test. Thanks. John Doe Telephone: 555 21803** From: email@example.com To: firstname.lastname@example.org Subject: Testing Hi, this is the SECOND test. Thanks. John Doe Telephone: 555 21803
Sub GetMessageFromMail() Dim mi As MailItem Dim vaMessages As Variant 'Get the email item - your method will be different Set mi = ActiveInspector.currentItem 'Split the body into an array. Every time it sees the 'string 'From:' it creates a new array item vaMessages = Split(mi.Body, "From:") 'The 0th message will be the two asterisks that precede the 'From: so to get the first message we need the 1 index of 'our zero based array Debug.Print vaMessages(1) 'Or you could get the last message by using UBound Debug.Print vaMessages(UBound(vaMessages)) End Sub