Outlook VBA - Find & Replace Incoming Emails
Posted
by
user1912198
on Stack Overflow
See other posts from Stack Overflow
or by user1912198
Published on 2012-12-18T08:51:32Z
Indexed on
2012/12/18
11:03 UTC
Read the original article
Hit count: 382
Good morning everyone at Stackoverflow,
I am trying to find a VBA script that finds and replaces a certain text in incoming e-mails. So far i've been unable to find such a script that is working.
I found several scripts to find and replace stuff in the e-mail but these don't work as a rule on incoming e-mails, they only work on outgoing / creating e-mails.
Does anyone have such a script that they can share with me? I would like to find & replace a certain text on every incoming e-mail.
I would really apreciate it!
Regards,
Kris
ps: I don't know how to program a whole VBA script, that's why I am asking here :)
Current Code:
Sub testing(MyMail As MailItem)
Dim mail As MailItem
Dim Inbox As Outlook.Folder
Set Inbox = Session.GetDefaultFolder(olFolderInbox)
For Each mail In Inbox.Items
'change subject
mail.Subject = "TESTING"
'replace body text
If mail.BodyFormat = olFormatHTML Then
mail.HTMLBody = Replace(mail.HTMLBody, "Test 123", "TESTING")
Else
mail.Body = Replace(mail.Body, "Test 123", "TESTING")
End If
Next mail
End Sub
© Stack Overflow or respective owner