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


  1. Ashok Rai says

    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

Leave a Reply

Please post long or more complicated questions at OutlookForums by

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