• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Assign a keyword to a message field for tracking

Slipstick Systems

› Developer › Assign a keyword to a message field for tracking

Last reviewed on January 4, 2018     6 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

Assign a keyword to a message field for tracking was last modified: January 4th, 2018 by Diane Poremsky

Related Posts:

  • How to automatically print sent messages
  • Add a keyword to the subject of all messages sent
  • Create Appointment From Email Automatically
  • Mark Sent Items as Read After Copying with a Rule

About 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.

Subscribe
Notify of
6 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Rahul (@guest_211093)
May 17, 2018 7:52 am
#211093

Greetings

1:- I want that macro pick up mails from outlook which contain subject line either "ABC" or "RE: ABC".

2:- I want that macro pick up mails from outlook which contain subject line either "ABC" or "RE: ABC" and also Body contain "APPROVAL" word.

so macro save these mails as a PDF in desired Location.

Please help.
Thanks in advance,

Regards'
Rahul Rawat

0
0
Reply
Joe KIM (@guest_210549)
March 8, 2018 4:28 am
#210549

Thank you for informative tips.

In the meantime, the billing information included in the email is stripped out when received. Is there any option to send email as it is, without losing such info?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Joe KIM
March 8, 2018 8:51 am
#210550

If you use rtf message format, the field should remain, but that only works with outlook and is best within an organization using exchange mailboxes.

0
-1
Reply
Joe KIM (@guest_211036)
Reply to  Diane Poremsky
May 11, 2018 5:13 am
#211036

Thank you for the comment. The message in rtf format is received by outlook 2013. But, the result is the same, with null in the BillingInformation field. The following is my codes. Kindly take a look if there is anything I missed.

Thank you in advance.
-------------------------------------------------------
Dim olApp As Outlook.Application
Dim myItem As Outlook.MailItem
Dim myInspector As Outlook.Inspector
Dim wdDoc As Word.Document
Dim wdRange As Word.Range

Set olApp = New Outlook.Application
Set myItem = olApp.CreateItem(olMailItem)

myItem.BillingInformation = "Case_Folder"
myItem.Display

'Copy from MS word--------------------------
Set myInspector = myItem.GetInspector
Set wdDoc = myInspector.WordEditor

If Not (wdDoc Is Nothing) Then
Set wdRange = wdDoc.Range(0, wdDoc.Characters.count)
wdRange.Paste
End If
myItem.Save
myItem.Send

Set wdRange = Nothing
Set mdDoc = Nothing
Set myInspector = Nothing
Set myItem = Nothing
Set olApp = Nothing

0
0
Reply
Ashok Rai (@guest_173856)
February 6, 2013 11:23 am
#173856

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

1
-1
Reply
Diane Poremsky (@guest_173864)
Reply to  Ashok Rai
February 7, 2013 7:16 am
#173864

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

2
-2
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 16

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Reset the New Outlook Profile
  • Save Attachments to the Hard Drive
  • Add Attachments and Set Email Fields During a Mail Merge
  • Outlook SecureTemp Files Folder
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment