3/8/2018 - 7:19 PM

Outlook Tips and Tricks

Outlook has a hidden feature, QueryBuilder, which can be very useful for those of you who need to define complex criteria for Search Folders or Advanced Find.

To add the QueryBuilder key to the registry, follow these steps:

  • Quit Outlook.
  • Click Start, and then click Run.
  • In the Open box, type regedit,and then click OK.
  • Locate the following key in the registry based on your installed version:
    • HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook
  • On the Edit menu, click New, click Key, and then type QueryBuilder for the key name.
  • Quit Registry Editor.
  • Restart Outlook.

NOTE: When setting up a query, if you need to change the and/or grouping, enter the condition first, then click "Add to List" button, and finally, choose AND/OR in the Logical Group.

' For more info:
' https://www.slipstick.com/developer/code-samples/change-item-count-folders-data-file/

' Open the VBA Editor by pressing Alt+F11 on your keyboard.
' To put the code in a module:
' Right click on Project1 and choose Insert > Module
' Copy and paste the macro into the new module.

Sub TotalUnreadCount()
    ' store is a pst file
    Dim App As New Outlook.Application
    Dim Stores As Outlook.Stores
    Dim Store As Outlook.Store
    Dim Root As Outlook.Folder

    On Error Resume Next
    Set Stores = App.Session.Stores
    For Each Store In Stores
        Set Root = Store.GetRootFolder
    ' Use If statemnet to apply to a specific data file
    ' Otherwise, all folders in ALL data files in the profile are changed
    ' display name is in the location field of the Properties dialog
    'If Root = "data file display name" Then
        ChangeShowCount Root
    'End If
End Sub

Private Sub ChangeShowCount(ByVal Root As Outlook.Folder)
    Dim Folders As Outlook.Folders
    Dim Folder As Outlook.Folder
    Dim Foldercount As Integer

    On Error Resume Next

    Set Folders = Root.Folders
    Foldercount = Folders.Count
    If Foldercount Then
        For Each Folder In Folders
        'ShowTotal Count
            Folder.ShowItemCount = olShowTotalItemCount
        'Show UnreadCount
            'Folder.ShowItemCount = olShowUnreadItemCount
            ChangeShowCount Folder
    End If
End Sub