Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook VBA - how to retrieve some text from the message

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
In Outlook VBA, if the body of the message is something like:

================================================
STARTING THE BODY MESSAGE

This is a test

Account Type: Support
Email: first.last@domain.com

END
================================================

How do you grep the account type, which is Support and the email address, which is first.last@domain.com out of this?
I'm trying to create an outlook macro that retrieves this information

Thanks!
 
You need to parse the [tt]MailItem.Body[/tt] to pull this information out. Quick thoughts:
Code:
Public Function GetKeyValue(BodyText as String, KeyValue as String) As String
Dim intKeyStart As Integer, intKeyLength as Integer
intKeyStart = InStr(BodyText, KeyValue) + Len(KeyValue)
[green]'Assumes that a carriage return [i]Chr(13)[/i] ends line[/green]
intKeyLength = InStr(intKeyStart, BodyText, Chr(13)) - intKeyStart
GetKeyValue = Trim(Mid(BodyText, intKeyStart, intKeyLength))
End Function

You can then call this function as many times as you need to return the value after the KeyValue:
[tt] var1 = GetKeyValue(MailItem.Body, "Account Type: ")
var2 = GetKeyValue(MailItem.Body, "Eamil: ")[/tt]
The return should be:
var1 = Support
var2 = first.last@domain.com
Hope this helps,
CMP

Instant programmer, just add coffee.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top