SpriteMonkey
01-08-2016, 10:01 AM
Having a problem with VBA scripting in Outlook. I have these emails that come in and they all have a generic subject header followed by a specific external part number. I want to run the script so it strips out all the junk and replaces the entire subject with just our internal part number. This script should examine the email subject, and if the subject contains XXXXXX001, then replaces the entire subject with YYYYYY001. Here are some examples of the input and the result:
Incoming Subject: "Automated XYZ Company Order: Part Description (02246744)"
Resulting Subject: "YYYYYY001"
Incoming Subject: "Automated ABC Plant Order: Part Description (02293577)"
Resulting Subject: "YYYYYY002"
Incoming Subject: "New 123 B2B Handling Order: Part Description (02267241)"
Resulting Subject: "YYYYYY003"
I started out with some code like this:
Sub EditSubject(Item As Outlook.MailItem)
Item.Subject = Replace(Item.Subject, "XXXXXX", "YYYYYY")
Item.Save
End Sub
But all that does is change the part number without stripping out all the junk. I need some kind of function that searches the subject for "02246744" or one of the other external part numbers, then replaces the whole subject with the matching internal part number.
Incoming Subject: "Automated XYZ Company Order: Part Description (02246744)"
Resulting Subject: "YYYYYY001"
Incoming Subject: "Automated ABC Plant Order: Part Description (02293577)"
Resulting Subject: "YYYYYY002"
Incoming Subject: "New 123 B2B Handling Order: Part Description (02267241)"
Resulting Subject: "YYYYYY003"
I started out with some code like this:
Sub EditSubject(Item As Outlook.MailItem)
Item.Subject = Replace(Item.Subject, "XXXXXX", "YYYYYY")
Item.Save
End Sub
But all that does is change the part number without stripping out all the junk. I need some kind of function that searches the subject for "02246744" or one of the other external part numbers, then replaces the whole subject with the matching internal part number.