Cheshi Mantu
Cheshi Mantu

Reputation: 41

Outlook 2013, Outlook 2016 VBA rearrange folders in folders tree

In Outlook versions after 2007 Microsoft added the possibility to manually arrange folders in folders tree (in Outlook 2007 folders were arranged alphabetically). Is there any possibility using VBA to arrange folders in the folders tree, e.g. put folder to the top when it contains new email? Thanks

Upvotes: 0

Views: 525

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

Starting from Outlook 2013 you can reorder folders however you like and Outlook would remember the order. The key property is PR_SORT_POSITION. Here’s the definition:

define PR_SORT_POSITION PROP_TAG( PT_BINARY, 0x3020)

Outlook will use this property as part of it’s sort order when requesting folders from a provider, so it’s important that your provider can handle sorting on a binary property – or can fake it when asked to sort by this property. Outlook will also use this property directly when deciding where to insert nodes in the visible tree, so it’s also important that your provider can return this property when Outlook looks for it on a folder.

There’s a second property Outlook will use for custom sort ordering:

define PR_SORT_PARENTID PROP_TAG( PT_BINARY, 0x3021)

As the name suggests, this property stores an entry ID which can be used to sort a folder under a different node than it’s natural parent. Normally, a folder will be sorted under the folder represented by PR_PARENT_ENTRYID. This property allows you to suggest a different parent for display.

By presetting these properties appropriately, you can direct Outlook in how you wish your provider’s folders to be sorted. And if you allow Outlook to write to these properties, you can preserve whatever sort order your users desire.

So, theoretically you can set these properties from VBA. The PropertyAccessor class can help you with such tasks. Also you may consider using a low-level code if you face with any restrictions from OOM, so any wrappers around Extended MAPI allows to bridge the gap (for example, Redemption).

Upvotes: 1

Related Questions