How to Quickly Copy All Color Categories from One Outlook PST File to Another via VBA

If you would like to copy all color categories from one Outlook PST file to another, it is a good option to utilize the VBA code shown in this article. It can assist you to get it in quick time.

At times, you may want to copy all color categories from one Outlook PST file to another file, simply in order to make the color categories of all your Outlook files unified and manage your Outlook items more effectively. Although you could also realize it by the way introduced in my previous article “How to Migrate Outlook Color Categories to another Computer”, it is more suggested to use the following means. It is much faster due to application of VBA code.

Quickly Copy All Color Categories from One Outlook PST File to Another

Copy All Color Categories from One Outlook PST File to Another

  1. To start with, launch your Outlook application.
  2. Then you could proceed to press “Alt + F11” key buttons in the main Outlook screen.
  3. Next in the emerging “Microsoft Visual Basic for Applications” window, you need to open a module that is not in use or straightly insert a new module.
  4. Subsequently, copy the following VBA code into this module.
Sub CopyColorCategories_FromAnOutlookPSTFile2Another()
    Dim objSourceStore As Outlook.Store
    Dim objTargetStore As Outlook.Store
    Dim objCategory As Category
    Dim strCategoryList As String
    Dim objFileSystem As Object
    Dim strTextFile As String
    Dim objTextFile As Object
    Dim objTextStream As Object
    Dim strLine As String
    Dim strArray() As String
    Dim objFoundCategory As Outlook.Category
    'Get the color categories from the source PST file
    'Change "John Smith" as per the display name of your source PST file
    Set objSourceStore = Application.Session.Stores.Item("John Smith")
    If objSourceStore.Categories.count > 0 Then
       For Each objCategory In objSourceStore.Categories
           strCategoryList = strCategoryList & objCategory.Name & ", " & objCategory.Color & ", " & objCategory.ShortcutKey & vbCrLf
    End If
    'Export the category list to a Text file
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    strTextFile = objFileSystem.GetSpecialFolder(2).Path & "\" & "Category List " & Format(Now, "yyyymmddhhmmss") & ".txt"
    Set objTextFile = objFileSystem.CreateTextFile(strTextFile, True)
    objTextFile.WriteLine (strCategoryList)
    'Specify the target PST file
    'Change "Johnny" as per the display name of your target PST file
    Set objTargetStore = Application.Session.Stores.Item("Jonny")
    'Read each line of the Text file
    Set objTextStream = objFileSystem.OpenTextFile(strTextFile)
    Do Until objTextStream.AtEndOfStream
       strLine = objTextStream.ReadLine
       If strLine <> "" Then
          'Add the color categories on basis of extracted Category name, color and shortcut key
          strArray = Split(strLine, ",")
          Set objFoundCategory = objTargetStore.Categories.Item(strArray(0))
          If objFoundCategory Is Nothing Then
             objTargetStore.Categories.Add strArray(0), strArray(1), strArray(2)
          End If
       End If
    MsgBox "Copy Successfully!", vbExclamation + vbOKOnly, "Copy Color Categories"
End Sub

VBA Code - Quickly Copy All Color Categories from One Outlook PST File to Another

  1. After that, you can exit the current Outlook VBA editor temporarily and click the “Macro Security” button under “Developer” tab.
  2. In the popup window, you should activate the “Enable all macros” option and hit “OK” to save the changes.Enable all macros
  3. Later you can turn back to VBA editor by clicking “Visual Basic” button or hit “Alt + F11” keys again.
  4. Next, access the previously added macro.
  5. Eventually, to trigger this new macro, just press F5 key button.
  6. After macro is finished, you will see that all the color categories of the source Outlook PST file have been copied to the specific target file.

Protect Outlook Data against Corruption

In spite of boasting of numerous capabilities, Outlook still can’t be immune from corruption. Therefore, if you are a regular Outlook user, you have to learn how to decrease the likelihood of Outlook corruption. For instance, you ought to keep virus at bay, get used to closing Outlook properly, getting hold of a top-ranking repair tool, like DataNumen Outlook Repair, and so on.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted mdf and outlook repair software products. For more information visit

Leave a Reply

Your email address will not be published. Required fields are marked *