Reputation: 1
I have 5 accounts in outlook and have 20 favorite folders taken from those that I would like to appear in the same order each time I open outlook. The order they appear each time is pretty random. Is there a way to run a script on opening that will sort the folders into same order each time I open
I have looked through the Office VBA reference and cant find anything there that helps
Upvotes: 0
Views: 107
Reputation: 49455
You can sort the folders in the Outlook UI by explicitly setting the PR_SORT_POSITION
property on each subfolder, for example, the following code shows the sort position of each folder in Outlook:
For Each folder In objMainFolder.Folders
folder_index_property = folder.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x30200102")
folder_index = folder.PropertyAccessor.BinaryToString(folder_index_property)
MsgBox folder.Name & ", " & CInt("&h0" & folder_index(0))
Next
To set up the sort order you need to use the PropertyAccessor.SetProperty method which sets the property specified by SchemaName
to the value specified by Value
. If the property does not exist and the SchemaName
contains a valid property specifier, then SetProperty
creates the property and assigns the value specified by Value
. If the property does exist and SchemaName
is valid, then SetProperty
assigns the property with the value specified by Value
.
Sub DemoPropertyAccessorSetProperty()
Dim myProp As String
Dim myValue As Integer
Dim oMail As Outlook.MailItem
Dim oPA As Outlook.PropertyAccessor
'Get first item in the inbox
Set oMail = _
Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
myProp = "http://schemas.microsoft.com/mapi/proptag/0x30200102"
myValue = 1
'Set value with SetProperty call
'If the property does not exist, then SetProperty
'adds the property to the object when saved.
'The type of the property is the type of the element
'passed in myValue.
On Error GoTo ErrTrap
Set oPA = oMail.PropertyAccessor
oPA.SetProperty myProp, myValue
'Save the item
oMail.Save
Exit Sub
ErrTrap:
Debug.Print Err.Number, Err.Description
End Sub
Upvotes: 0