0

I am writing VBA code in Outlook 2007 to extract email address from emails.

I am able to read the body as a whole through a variable

How do I extract email address from the variable?

niton
  • 8,771
  • 21
  • 32
  • 52

2 Answers2

0

One method is described here.

sString = "my1@email.com xxx my2@email.com yyy my3@email.com"
asString = Split(sString, " ")
For i = 0 To UBound(asString)
    If asString(i) Like "*@*.*" Then
        sEmail = sEmail & "," & asString(i)
    End If
Next

MsgBox Mid(sEmail, 2)
Community
  • 1
  • 1
niton
  • 8,771
  • 21
  • 32
  • 52
0

Why the body? Have you looked at the MailItem.Recipients collection (Recipient.Address) and the MailItem.SenderEmailAddress property?

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I believe the addresses are part of body of the mail. Not recipients. – niton Apr 06 '15 at 16:53
  • Is that what the *original poster* has in mind? I am trying to see why the body rather than recipients need to be processed. And if the data is in the message body, who put it there? Is it in a special format? – Dmitry Streblechenko Apr 06 '15 at 17:47
  • The body of the email is in the "variable". The OP wants to parse the variable. Future searchers may find this is the answer to their question. – niton Apr 06 '15 at 22:14
  • You are missing my point: is the OP parsing the message body because he/she is unaware of the other message properties? Or because the message was sent by some automatized process that populates the body with email addresses? – Dmitry Streblechenko Apr 06 '15 at 22:35