Solved

How to Change the subject of emails on one folder depending on the sender

Posted on 2008-06-11
6
387 Views
Last Modified: 2013-11-27
I've been requested to create a macro that will change the subject of a email  message depending on the sender.
the problem is that the user receives many emails regarding orders, the messages are place in a folder by a rule and I want to change the subject
i.e.
i receive a message from john@doe.com with the subject
"Status of Shipments 01/01/08"
I want to be able to change the subject to read:
"ONTARIO - Status of Shipments 01/01/08"

My Idea is to be able to select a number of emails on the personal folder file
lets say the name of the folder is "IBA"

So the logic for this macro is
for all messages selected in folder "IBA" if the sender is John@Doe.com then
take the subject and add at the begining of the subject "ONTARIO - "
if the sender is Jane@doe.com then then take the subject
and add at the begining of the subject "VERNON - "
0
Comment
Question by:TOPIO
  • 3
  • 3
6 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
Hi, TOPIO.

This should do it.  I haven't tested it though.
Sub FixSubject()

    Dim olkMsg As Outlook.MailItem

    For Each olkMsg In Application.ActiveExplorer.Selection

        Select Case olkMsg.SenderEmailAddress

            'Create a Case statement like one of these for each possible address

            'The address must be an exact match including case

            Case "John@Doe.com"

                olkMsg.Subject = "ONTARIO - " & olkMsg.Subject

            Case "Jane@Doe.com"

                olkMsg.Subject = "VERNON - " & olkMsg.Subject

        End Select

        olkMsg.Save

    Next

    Set olkMsg = Nothing

    MsgBox "All done!"

End Sub

Open in new window

0
 
LVL 10

Author Comment

by:TOPIO
Comment Utility
I get the following error:

Select Case olkMsg.SenderEmailAddress <<<<Object Does not Support this property or method
0
 
LVL 10

Author Comment

by:TOPIO
Comment Utility
I corrected the previous error by changing
strOriginAddress = olkMsg.SenderName

however when I run the macro on meeting requests I get the following error

For Each olkMsg In Application.ActiveExplorer.Selection <<< Run time error '13' Type Mismatch
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Apologies for the first error.  I didn't know what version of Outlook you're using.

The second error would occur if something other than a mail message was selected.  Either insure that all the items you've selected are mail items, or change this line

    Dim olkMsg As Outlook.MailItem

to

    Dim olkMsg As Object
0
 
LVL 10

Author Comment

by:TOPIO
Comment Utility
THANKS!
FINAL VERSION  IS BELOW

Sub FixSubjectForIBAMails()

    Dim olkMsg As Object

    Dim strOriginAddress As String

    

    For Each olkMsg In Application.ActiveExplorer.Selection

    

    strOriginAddress = olkMsg.SenderName

                      

                        

  '  MsgBox strOriginAddress

        Select Case strOriginAddress

            'Create a Case statement like one of these for each possible address

            'The address must be an exact match including case

            Case "Garcia, Carmen"

                olkMsg.Subject = "VERNON - " & olkMsg.Subject

            Case "Ibarra, David"

                olkMsg.Subject = "VERNON - " & olkMsg.Subject

            Case "Olmos, Claudia"

                olkMsg.Subject = "VERNON - " & olkMsg.Subject

            Case "Pedroza, Norma"

                olkMsg.Subject = "ONTARIO - " & olkMsg.Subject

             Case "Vega, Vanessa"

                olkMsg.Subject = "VERNON - " & olkMsg.Subject

                

                

        End Select

        olkMsg.Save

    Next

    Set olkMsg = Nothing

    MsgBox "All done!"

End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome.  Glad I could help out.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now