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"
   End If
  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"

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

About Diane Poremsky

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 Outlook forums by

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

  1. Ashok Rai

    I am looking for Macro in outlook 2007 , where i want to restrict few mail id like,, 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.
    If is sending the mail to or then it is good to go. 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

    1. Diane Poremsky

      I have a macro here somewhere that checks addresses. It's basically the macro here but with different conditions.

Leave a Reply

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

This site uses XenWord.