Rikard
Rikard

Reputation: 43

How do I use Outlook macro to search for strings between characters?

I am trying to go through all mails in a folder and create a new mail, to an address specified in the first mail.

I need to search through the body of the email for the following: <[email protected]> and copy the email address between the two angle brackets to use it as the recipient for the new email.

Upvotes: 1

Views: 1332

Answers (1)

Max
Max

Reputation: 759

you have to find out where the < and > sign ist and choose the text inbetween:

NOT TESTED

dim start_str as integer
dim end_str as integer
dim mymail as string
start_str = instr(mailitem.body,"<") + 1
end_str = instr(mailitem.body,">") - start_str
mymail = mid(mailitem.body, start_str, end_str)

I am not quite sure you might hsve to add +1 or -1 in the start- or end-string, but otherwise it should work. You only have a Problem, if the characters < or > are exist in the mail another time befor the mail-address.

I hope this helps, Max

Upvotes: 1

Related Questions