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