Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-06-11
6
395 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
ID: 21772413
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
ID: 21774629
I get the following error:

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

Author Comment

by:TOPIO
ID: 21774680
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 76

Expert Comment

by:David Lee
ID: 21774753
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
ID: 21774788
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
ID: 21774955
You're welcome.  Glad I could help out.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

860 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