Assign a keyword to a message field for tracking

Last reviewed on July 26, 2012   —  2 comments

This macro scans all messages in a folder, looking for a unique keyword and if found, enters a user name into the Billing Information field.

Usage scenario: multiple people send email from a shared mailbox. Each person is has a unique code in the signature they use that identifies who is handling the message. The manager wants scan the message list to see who is the message. To do this, the actual sender's name needs to be added to a field - since few sites use the billing information field, it is suitable for this purpose.

To use, the manager runs the macro on the Inbox (or selected folder). The If.. end if block needs to be repeated for each user. A function using an array of keywords and user names would be better.

To add a value to the billing information field when a message is sent, use the second macro.

Public Sub SetBillingField()
    Dim itm As Object
    Set Items = Application.ActiveExplorer.CurrentFolder.Items
     
    For Each itm In Items
    If InStr(1, itm.Body, "keyword", vbTextCompare) > 0 Then
      itm.BillingInformation = "user name"
      itm.Save
   End If
        Next
  Set  itm = nothing

End Sub

Add data to Billing Information field after message is sent

Use this to add data to the billing information field when the sent message is added to the Sent Items folder.

Dim WithEvents sentMsg As Items
 
Private Sub Application_Startup()
   Dim NS As Outlook.NameSpace
   Set NS = Application.GetNamespace("MAPI")
   Set sentMsg = NS.GetDefaultFolder(olFolderSentMail).Items
   Set NS = Nothing
End Sub
 
Private Sub sentMsg_ItemAdd(ByVal Item As Object)

Item.BillingInformation = "code"

Item.Save
End Sub

Add data to the Billing Information field when sent

Warning: when you use the ItemSend method, the recipient may be able to see the billing information.

Private Sub Application_ItemSend(ByVal Item As Object)
 
Item.BillingInformation = "code"

End Sub

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlookforums.

2 responses to “Assign a keyword to a message field for tracking”

  1. Ashok Rai

    Hi,
    I am looking for Macro in outlook 2007 , where i want to restrict few mail id like abc@gmail.com, xyz@gmail.com, whether it is appearing in the "To" "CC" or "BCC" option and secondly only prime mail id can send the mails to above e.g. 123@gmail.com.
    Case:-
    If 123@gmail.com is sending the mail to abc@gmail.com or xyz@gmail.com then it is good to go. 234@gmail.com is sending then it should give the prompt that you are not authorized to send the mail.
    Hope you will able to make out what i am looking for.
    Thank you

Leave a Reply

If the Post Coment button disappears, press your Tab key.